OSDN Git Service

Implement dwarf2 exception handling for the ARM.
[pf3gnuchains/gcc-fork.git] / gcc / dwarf2out.c
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).
7
8 This file is part of GNU CC.
9
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.
14
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.
19
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.  */
24
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.  */
34
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.  */
40
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"
60
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
69
70 /* Decide whether we want to emit frame unwind information for the current
71    translation unit.  */
72
73 int
74 dwarf2out_do_frame ()
75 {
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
84           );
85 }
86
87 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
88
89 /* How to start an assembler comment.  */
90 #ifndef ASM_COMMENT_START
91 #define ASM_COMMENT_START ";#"
92 #endif
93
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;
97
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.  */
102
103 typedef union dw_cfi_oprnd_struct
104 {
105   unsigned long dw_cfi_reg_num;
106   long int dw_cfi_offset;
107   char *dw_cfi_addr;
108 }
109 dw_cfi_oprnd;
110
111 typedef struct dw_cfi_struct
112 {
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;
117 }
118 dw_cfi_node;
119
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.  */
125
126 typedef struct dw_fde_struct
127 {
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;
133 }
134 dw_fde_node;
135
136 /* Maximum size (in bytes) of an artificially generated label.   */
137 #define MAX_ARTIFICIAL_LABEL_BYTES      30
138
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.  */
143
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
150
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.  */
154
155 #ifndef DWARF_OFFSET_SIZE
156 #define DWARF_OFFSET_SIZE 4
157 #endif
158
159 #define DWARF_VERSION 2
160
161 /* Round SIZE up to the nearest BOUNDARY.  */
162 #define DWARF_ROUND(SIZE,BOUNDARY) \
163   ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
164
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
171
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;
175
176 /* Number of elements currently allocated for fde_table.  */
177 static unsigned fde_table_allocated;
178
179 /* Number of elements in fde_table currently in use.  */
180 static unsigned fde_table_in_use;
181
182 /* Size (in elements) of increments by which we may expand the
183    fde_table.  */
184 #define FDE_TABLE_INCREMENT 256
185
186 /* A list of call frame insns for the CIE.  */
187 static dw_cfi_ref cie_cfi_head;
188
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;
195
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;
201
202 /* Forward declarations for functions defined in this file.  */
203
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 reg_number              PARAMS ((rtx));
222 static void dwarf2out_stack_adjust      PARAMS ((rtx));
223 static void dwarf2out_frame_debug_expr  PARAMS ((rtx, char *));
224
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.  */
229
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 */
241
242 #ifndef ASM_BYTE_OP
243 #define ASM_BYTE_OP             ".byte"
244 #endif
245
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)
249
250 /* Pseudo-op for defining a new section.  */
251 #ifndef SECTION_ASM_OP
252 #define SECTION_ASM_OP  ".section"
253 #endif
254
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
266
267 #ifndef FRAME_SECTION
268 #define FRAME_SECTION           ".debug_frame"
269 #endif
270
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"
283
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.  */
287
288 #ifndef ASM_OUTPUT_SECTION
289 #define ASM_OUTPUT_SECTION(FILE, SECTION) \
290   fprintf ((FILE), SECTION_FORMAT, SECTION_ASM_OP, SECTION)
291 #endif
292
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
297
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
306
307 #ifdef UNALIGNED_INT_ASM_OP
308
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
313
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
319
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
328
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
337
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
346
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
355
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
362
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
370
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
377
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
384
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
389
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
394
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
400
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
406
407 #ifndef ASM_OUTPUT_DWARF_DATA8
408 #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE)               \
409   do {                                                                  \
410     if (WORDS_BIG_ENDIAN)                                               \
411       {                                                                 \
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));\
414       }                                                                 \
415     else                                                                \
416       {                                                                 \
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)); \
419       }                                                                 \
420   } while (0)
421 #endif
422
423 #else /* UNALIGNED_INT_ASM_OP */
424
425 /* We don't have unaligned support, let's hope the normal output works for
426    .debug_frame.  */
427
428 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
429   assemble_integer (gen_rtx_SYMBOL_REF (Pmode, LABEL), PTR_SIZE, 1)
430
431 #define ASM_OUTPUT_DWARF_OFFSET4(FILE,LABEL) \
432   assemble_integer (gen_rtx_SYMBOL_REF (SImode, LABEL), 4, 1)
433
434 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
435   assemble_integer (gen_rtx_SYMBOL_REF (SImode, LABEL), 4, 1)
436
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)
442   
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)
448
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)
454
455 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
456   ASM_OUTPUT_DWARF_DELTA4 (FILE,LABEL1,LABEL2)
457
458 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
459   assemble_integer (GEN_INT (VALUE), 4, 1)
460
461 #endif /* UNALIGNED_INT_ASM_OP */
462
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 */
476
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++)                                                \
488       {                                                                       \
489           register int c = p[i];                                              \
490           if (c == '\"' || c == '\\')                                         \
491             putc ('\\', FILE);                                                \
492           if (ISPRINT(c))                                                     \
493             putc (c, FILE);                                                   \
494           else                                                                \
495             {                                                                 \
496               fprintf (FILE, "\\%o", c);                                      \
497             }                                                                 \
498       }                                                                       \
499     fprintf (FILE, "\\0\"");                                                  \
500   }                                                                           \
501   while (0)
502 #endif
503
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
514
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
520
521 /* Hook used by __throw.  */
522
523 rtx
524 expand_builtin_dwarf_fp_regnum ()
525 {
526   return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM));
527 }
528
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
534
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).  */
537
538 static inline char *
539 stripattributes (s)
540      const char *s;
541 {
542   char *stripped = xmalloc (strlen (s) + 2);
543   char *p = stripped;
544
545   *p++ = '*';
546
547   while (*s && *s != ',')
548     *p++ = *s++;
549
550   *p = '\0';
551   return stripped;
552 }
553
554 /* Return the register number described by a given RTL node.  */
555
556 static unsigned
557 reg_number (rtl)
558      register rtx rtl;
559 {
560   register unsigned regno = REGNO (rtl);
561
562   if (regno >= FIRST_PSEUDO_REGISTER)
563     {
564       warning ("internal regno botch: regno = %d\n", regno);
565       regno = 0;
566     }
567
568   regno = DBX_REGISTER_NUMBER (regno);
569   return regno;
570 }
571
572 /* Generate code to initialize the register size table.  */
573
574 void
575 expand_builtin_init_dwarf_reg_sizes (address)
576      tree address;
577 {
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);
582
583   for (i = 0; i < DWARF_FRAME_REGISTERS; ++i)
584     {
585       int offset = i * GET_MODE_SIZE (mode);
586       int size = GET_MODE_SIZE (reg_raw_mode[i]);
587
588       emit_move_insn (change_address (mem, mode,
589                                       plus_constant (addr, offset)),
590                       GEN_INT (size));
591     }
592 }
593
594 /* Convert a DWARF call frame info. operation to its string name */
595
596 static const char *
597 dwarf_cfi_name (cfi_opc)
598      register unsigned cfi_opc;
599 {
600   switch (cfi_opc)
601     {
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";
638
639     /* SGI/MIPS specific */
640     case DW_CFA_MIPS_advance_loc8:
641       return "DW_CFA_MIPS_advance_loc8";
642
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";
650
651     default:
652       return "DW_CFA_<unknown>";
653     }
654 }
655
656 /* Return a pointer to a newly allocated Call Frame Instruction.  */
657
658 static inline dw_cfi_ref
659 new_cfi ()
660 {
661   register dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
662
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;
666
667   return cfi;
668 }
669
670 /* Add a Call Frame Instruction to list of instructions.  */
671
672 static inline void
673 add_cfi (list_head, cfi)
674      register dw_cfi_ref *list_head;
675      register dw_cfi_ref cfi;
676 {
677   register dw_cfi_ref *p;
678
679   /* Find the end of the chain.  */
680   for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
681     ;
682
683   *p = cfi;
684 }
685
686 /* Generate a new label for the CFI info to refer to.  */
687
688 char *
689 dwarf2out_cfi_label ()
690 {
691   static char label[20];
692   static unsigned long label_num = 0;
693   
694   ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++);
695   ASM_OUTPUT_LABEL (asm_out_file, label);
696
697   return label;
698 }
699
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.  */
702
703 static void
704 add_fde_cfi (label, cfi)
705      register char *label;
706      register dw_cfi_ref cfi;
707 {
708   if (label)
709     {
710       register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
711
712       if (*label == 0)
713         label = dwarf2out_cfi_label ();
714
715       if (fde->dw_fde_current_label == NULL
716           || strcmp (label, fde->dw_fde_current_label) != 0)
717         {
718           register dw_cfi_ref xcfi;
719
720           fde->dw_fde_current_label = label = xstrdup (label);
721
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);
727         }
728
729       add_cfi (&fde->dw_fde_cfi, cfi);
730     }
731
732   else
733     add_cfi (&cie_cfi_head, cfi);
734 }
735
736 /* Subroutine of lookup_cfa.  */
737
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;
743 {
744   switch (cfi->dw_cfi_opc)
745     {
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;
758     }
759 }
760
761 /* Find the previous value for the CFA.  */
762
763 static void
764 lookup_cfa (regp, offsetp)
765      register unsigned long *regp;
766      register long *offsetp;
767 {
768   register dw_cfi_ref cfi;
769
770   *regp = (unsigned long) -1;
771   *offsetp = 0;
772
773   for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
774     lookup_cfa_1 (cfi, regp, offsetp);
775
776   if (fde_table_in_use)
777     {
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);
781     }
782 }
783
784 /* The current rule for calculating the DWARF2 canonical frame address.  */
785 static unsigned long cfa_reg;
786 static long cfa_offset;
787
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;
792
793 /* The running total of the size of arguments pushed onto the stack.  */
794 static long args_size;
795
796 /* The last args_size we actually output.  */
797 static long old_args_size;
798
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.  */
802
803 void
804 dwarf2out_def_cfa (label, reg, offset)
805      register char *label;
806      register unsigned reg;
807      register long offset;
808 {
809   register dw_cfi_ref cfi;
810   unsigned long old_reg;
811   long old_offset;
812
813   cfa_reg = reg;
814   cfa_offset = offset;
815   if (cfa_store_reg == reg)
816     cfa_store_offset = offset;
817
818   reg = DWARF_FRAME_REGNUM (reg);
819   lookup_cfa (&old_reg, &old_offset);
820
821   if (reg == old_reg && offset == old_offset)
822     return;
823
824   cfi = new_cfi ();
825
826   if (reg == old_reg)
827     {
828       cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
829       cfi->dw_cfi_oprnd1.dw_cfi_offset = offset;
830     }
831
832 #ifndef MIPS_DEBUGGING_INFO  /* SGI dbx thinks this means no offset.  */
833   else if (offset == old_offset && old_reg != (unsigned long) -1)
834     {
835       cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
836       cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
837     }
838 #endif
839
840   else
841     {
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;
845     }
846
847   add_fde_cfi (label, cfi);
848 }
849
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.  */
854
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;
861 {
862   register dw_cfi_ref cfi = new_cfi ();
863
864   cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
865
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)
869     {
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;
876
877       offset /= DWARF_CIE_DATA_ALIGNMENT;
878       if (offset < 0)
879         {
880           cfi->dw_cfi_opc = DW_CFA_GNU_negative_offset_extended;
881           offset = -offset;
882         }
883       cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
884     }
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
889     {
890       cfi->dw_cfi_opc = DW_CFA_register;
891       cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
892     }
893
894   add_fde_cfi (label, cfi);
895 }
896
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.
900    
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.  */
903
904 void
905 dwarf2out_window_save (label)
906      register char * label;
907 {
908   register dw_cfi_ref cfi = new_cfi ();
909   cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
910   add_fde_cfi (label, cfi);
911 }
912
913 /* Add a CFI to update the running total of the size of arguments
914    pushed onto the stack.  */
915
916 void
917 dwarf2out_args_size (label, size)
918      char *label;
919      long size;
920 {
921   register dw_cfi_ref cfi;
922
923   if (size == old_args_size)
924     return;
925   old_args_size = size;
926
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);
931 }
932
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.  */
935
936 void
937 dwarf2out_reg_save (label, reg, offset)
938      register char * label;
939      register unsigned reg;
940      register long offset;
941 {
942   reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset);
943 }
944
945 /* Entry point for saving the return address in the stack.
946    LABEL and OFFSET are passed to reg_save.  */
947
948 void
949 dwarf2out_return_save (label, offset)
950      register char * label;
951      register long offset;
952 {
953   reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset);
954 }
955
956 /* Entry point for saving the return address in a register.
957    LABEL and SREG are passed to reg_save.  */
958
959 void
960 dwarf2out_return_reg (label, sreg)
961      register char * label;
962      register unsigned sreg;
963 {
964   reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0);
965 }
966
967 /* Record the initial position of the return address.  RTL is
968    INCOMING_RETURN_ADDR_RTX.  */
969
970 static void
971 initial_return_save (rtl)
972      register rtx rtl;
973 {
974   unsigned int reg = (unsigned int) -1;
975   long offset = 0;
976
977   switch (GET_CODE (rtl))
978     {
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))
987         {
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 ();
1005         }
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 ();
1017     }
1018
1019   reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa_offset);
1020 }
1021
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.  */
1025
1026 static void
1027 dwarf2out_stack_adjust (insn)
1028      rtx insn;
1029 {
1030   long offset;
1031   char *label;
1032
1033   if (! asynchronous_exceptions && GET_CODE (insn) == CALL_INSN)
1034     {
1035       /* Extract the size of the args from the CALL rtx itself.  */
1036
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;
1045     }
1046
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;
1052
1053   if (GET_CODE (insn) == BARRIER)
1054     {
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
1063     }
1064   else if (GET_CODE (PATTERN (insn)) == SET)
1065     {
1066       rtx src, dest;
1067       enum rtx_code code;
1068
1069       insn = PATTERN (insn);
1070       src = SET_SRC (insn);
1071       dest = SET_DEST (insn);
1072
1073       if (dest == stack_pointer_rtx)
1074         {
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;
1081
1082           offset = INTVAL (XEXP (src, 1));
1083         }
1084       else if (GET_CODE (dest) == MEM)
1085         {
1086           /* (set (mem (pre_dec (reg sp))) (foo)) */
1087           src = XEXP (dest, 0);
1088           code = GET_CODE (src);
1089
1090           if (! (code == PRE_DEC || code == PRE_INC)
1091               || XEXP (src, 0) != stack_pointer_rtx)
1092             return;
1093
1094           offset = GET_MODE_SIZE (GET_MODE (dest));
1095         }
1096       else
1097         return;
1098
1099       if (code == PLUS || code == PRE_INC)
1100         offset = -offset;
1101     }
1102   else
1103     return;
1104
1105   if (offset == 0)
1106     return;
1107
1108   if (cfa_reg == STACK_POINTER_REGNUM)
1109     cfa_offset += offset;
1110
1111 #ifndef STACK_GROWS_DOWNWARD
1112   offset = -offset;
1113 #endif
1114   args_size += offset;
1115   if (args_size < 0)
1116     args_size = 0;
1117
1118   label = dwarf2out_cfi_label ();
1119   dwarf2out_def_cfa (label, cfa_reg, cfa_offset);
1120   dwarf2out_args_size (label, args_size);
1121 }
1122
1123 /* A temporary register used in adjusting SP or setting up the store_reg.  */
1124 static unsigned cfa_temp_reg;
1125
1126 /* A temporary value used in adjusting SP or setting up the store_reg.  */
1127 static long cfa_temp_value;
1128
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. */
1132
1133 static void
1134 dwarf2out_frame_debug_expr (expr, label)
1135      rtx expr;
1136      char *label;
1137 {
1138   rtx src, dest;
1139   long offset;
1140     
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. */
1146
1147   if (GET_CODE (expr) == PARALLEL)
1148     { 
1149       int par_index;
1150       int limit = XVECLEN (expr, 0);
1151
1152       for (par_index = 0; par_index < limit; par_index++)
1153         {
1154           rtx x = XVECEXP (expr, 0, par_index);
1155           
1156           if (GET_CODE (x) == SET &&
1157               (RTX_FRAME_RELATED_P (x) || par_index == 0))
1158             dwarf2out_frame_debug_expr (x, label);
1159         }
1160       return;
1161     }
1162   
1163   if (GET_CODE (expr) != SET)
1164     abort ();
1165
1166   src = SET_SRC (expr);
1167   dest = SET_DEST (expr);
1168
1169   switch (GET_CODE (dest))
1170     {
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))
1175         {
1176           /* Setting FP from SP.  */
1177         case REG:
1178           if (cfa_reg != (unsigned) REGNO (src))
1179             abort ();
1180
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;
1187
1188         case PLUS:
1189         case MINUS:
1190           if (dest == stack_pointer_rtx)
1191             {
1192               /* Adjusting SP.  */
1193               switch (GET_CODE (XEXP (src, 1)))
1194                 {
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 ();
1205                 }
1206
1207               if (XEXP (src, 0) == hard_frame_pointer_rtx)
1208                 {
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;
1213                 }
1214               else if (XEXP (src, 0) != stack_pointer_rtx)
1215                 abort ();
1216
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;
1223             }
1224           else if (dest == hard_frame_pointer_rtx)
1225             {
1226               /* Either setting the FP from an offset of the SP,
1227                  or adjusting the FP */
1228               if (! frame_pointer_needed)
1229                 abort ();
1230
1231               if (GET_CODE (XEXP (src, 0)) == REG
1232                   && (unsigned) REGNO (XEXP (src, 0)) == cfa_reg
1233                   && GET_CODE (XEXP (src, 1)) == CONST_INT)
1234                 {
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;
1240                 }
1241               else 
1242                 abort();
1243             }
1244           else
1245             {
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;
1256             }
1257           break;
1258
1259         case CONST_INT:
1260           cfa_temp_reg = REGNO (dest);
1261           cfa_temp_value = INTVAL (src);
1262           break;
1263
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;
1272
1273         default:
1274           abort ();
1275         }
1276       dwarf2out_def_cfa (label, cfa_reg, cfa_offset);
1277       break;
1278
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)))
1285         {
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;
1292
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;
1299
1300           offset = -cfa_store_offset;
1301           break;
1302
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;
1309
1310           if (cfa_store_reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1311             abort ();
1312           offset -= cfa_store_offset;
1313           break;
1314
1315           /* Without an offset.  */
1316         case REG:
1317           if (cfa_store_reg != (unsigned) REGNO (XEXP (dest, 0)))
1318             abort();
1319           offset = -cfa_store_offset;
1320           break;
1321
1322         default:
1323           abort ();
1324         }
1325       dwarf2out_def_cfa (label, cfa_reg, cfa_offset);
1326       dwarf2out_reg_save (label, REGNO (src), offset);
1327       break;
1328
1329     default:
1330       abort ();
1331     }
1332 }
1333
1334
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.  */
1338
1339 void
1340 dwarf2out_frame_debug (insn)
1341      rtx insn;
1342 {
1343   char *label;
1344   rtx src;
1345
1346   if (insn == NULL_RTX)
1347     {
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;
1358     }
1359
1360   if (! RTX_FRAME_RELATED_P (insn))
1361     {
1362       dwarf2out_stack_adjust (insn);
1363       return;
1364     }
1365
1366   label = dwarf2out_cfi_label ();
1367     
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);
1373
1374   dwarf2out_frame_debug_expr (insn, label);
1375 }
1376
1377 /* Return the size of an unsigned LEB128 quantity.  */
1378
1379 static inline unsigned long
1380 size_of_uleb128 (value)
1381      register unsigned long value;
1382 {
1383   register unsigned long size = 0;
1384   register unsigned byte;
1385
1386   do
1387     {
1388       byte = (value & 0x7f);
1389       value >>= 7;
1390       size += 1;
1391     }
1392   while (value != 0);
1393
1394   return size;
1395 }
1396
1397 /* Return the size of a signed LEB128 quantity.  */
1398
1399 static inline unsigned long
1400 size_of_sleb128 (value)
1401      register long value;
1402 {
1403   register unsigned long size = 0;
1404   register unsigned byte;
1405
1406   do
1407     {
1408       byte = (value & 0x7f);
1409       value >>= 7;
1410       size += 1;
1411     }
1412   while (!(((value == 0) && ((byte & 0x40) == 0))
1413            || ((value == -1) && ((byte & 0x40) != 0))));
1414
1415   return size;
1416 }
1417
1418 /* Output an unsigned LEB128 quantity.  */
1419
1420 static void
1421 output_uleb128 (value)
1422      register unsigned long value;
1423 {
1424   unsigned long save_value = value;
1425
1426   fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP);
1427   do
1428     {
1429       register unsigned byte = (value & 0x7f);
1430       value >>= 7;
1431       if (value != 0)
1432         /* More bytes to follow.  */
1433         byte |= 0x80;
1434
1435       fprintf (asm_out_file, "0x%x", byte);
1436       if (value != 0)
1437         fprintf (asm_out_file, ",");
1438     }
1439   while (value != 0);
1440
1441   if (flag_debug_asm)
1442     fprintf (asm_out_file, "\t%s ULEB128 0x%lx", ASM_COMMENT_START, save_value);
1443 }
1444
1445 /* Output an signed LEB128 quantity.  */
1446
1447 static void
1448 output_sleb128 (value)
1449      register long value;
1450 {
1451   register int more;
1452   register unsigned byte;
1453   long save_value = value;
1454
1455   fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP);
1456   do
1457     {
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;
1465
1466       fprintf (asm_out_file, "0x%x", byte);
1467       if (more)
1468         fprintf (asm_out_file, ",");
1469     }
1470
1471   while (more);
1472   if (flag_debug_asm)
1473     fprintf (asm_out_file, "\t%s SLEB128 %ld", ASM_COMMENT_START, save_value);
1474 }
1475
1476 /* Output a Call Frame Information opcode and its operand(s).  */
1477
1478 static void
1479 output_cfi (cfi, fde)
1480      register dw_cfi_ref cfi;
1481      register dw_fde_ref fde;
1482 {
1483   if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1484     {
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);
1492     }
1493
1494   else if (cfi->dw_cfi_opc == DW_CFA_offset)
1495     {
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);
1502
1503       fputc ('\n', asm_out_file);
1504       output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
1505       fputc ('\n', asm_out_file);
1506     }
1507   else if (cfi->dw_cfi_opc == DW_CFA_restore)
1508     {
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);
1515
1516       fputc ('\n', asm_out_file);
1517     }
1518   else
1519     {
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));
1524
1525       fputc ('\n', asm_out_file);
1526       switch (cfi->dw_cfi_opc)
1527         {
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;
1595         }
1596      }
1597 }
1598
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.  */
1602
1603 static void
1604 output_call_frame_info (for_eh)
1605      int for_eh;
1606 {
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
1614
1615   /* Do we want to include a pointer to the exception table?  */
1616   int eh_ptr = for_eh && exception_table_p ();
1617
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)
1621     {
1622       for (i = 0; i < fde_table_in_use; ++i)
1623         if (! fde_table[i].nothrow)
1624           goto found;
1625       return;
1626     found:;
1627     }
1628
1629   fputc ('\n', asm_out_file);
1630
1631   /* We're going to be generating comments, so turn on app.  */
1632   if (flag_debug_asm)
1633     app_enable ();
1634
1635   if (for_eh)
1636     {
1637 #ifdef EH_FRAME_SECTION
1638       EH_FRAME_SECTION ();
1639 #else
1640       tree label = get_file_function_name ('F');
1641
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__");
1648     }
1649   else
1650     ASM_OUTPUT_SECTION (asm_out_file, FRAME_SECTION);
1651
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);
1670
1671   fputc ('\n', asm_out_file);
1672   ASM_OUTPUT_LABEL (asm_out_file, l1);
1673
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);
1680
1681   if (flag_debug_asm)
1682     fprintf (asm_out_file, "\t%s CIE Identifier Tag", ASM_COMMENT_START);
1683
1684   fputc ('\n', asm_out_file);
1685   if (! for_eh && DWARF_OFFSET_SIZE == 8)
1686     {
1687       ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
1688       fputc ('\n', asm_out_file);
1689     }
1690
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);
1694
1695   fputc ('\n', asm_out_file);
1696   if (eh_ptr)
1697     {
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)
1703         {
1704           ASM_OUTPUT_DWARF_STRING (asm_out_file, "eh");
1705           fprintf (asm_out_file, "\t%s CIE Augmentation", ASM_COMMENT_START);
1706         }
1707       else
1708         {
1709           ASM_OUTPUT_ASCII (asm_out_file, "eh", 3);
1710         }
1711       fputc ('\n', asm_out_file);
1712
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);
1717     }
1718   else
1719     {
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);
1724     }
1725
1726   fputc ('\n', asm_out_file);
1727   output_uleb128 (1);
1728   if (flag_debug_asm)
1729     fprintf (asm_out_file, " (CIE Code Alignment Factor)");
1730
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)");
1735
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);
1740
1741   fputc ('\n', asm_out_file);
1742
1743   for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
1744     output_cfi (cfi, NULL);
1745
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
1755
1756   /* Loop through all of the FDE's.  */
1757   for (i = 0; i < fde_table_in_use; ++i)
1758     {
1759       fde = &fde_table[i];
1760
1761       /* Don't emit EH unwind info for leaf functions.  */
1762       if (for_eh && fde->nothrow)
1763         continue;
1764
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);
1783
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);
1798
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);
1803
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);
1809
1810       fputc ('\n', asm_out_file);
1811
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);
1817
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
1827     }
1828 #ifndef EH_FRAME_SECTION
1829   if (for_eh)
1830     {
1831       /* Emit terminating zero for table.  */
1832       ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
1833       fputc ('\n', asm_out_file);
1834     }
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
1841
1842   /* Turn off app to make assembly quicker.  */
1843   if (flag_debug_asm)
1844     app_disable ();
1845 }
1846
1847 /* Output a marker (i.e. a label) for the beginning of a function, before
1848    the prologue.  */
1849
1850 void
1851 dwarf2out_begin_prologue ()
1852 {
1853   char label[MAX_ARTIFICIAL_LABEL_BYTES];
1854   register dw_fde_ref fde;
1855
1856   ++current_funcdef_number;
1857
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);
1863
1864   /* Expand the fde table if necessary.  */
1865   if (fde_table_in_use == fde_table_allocated)
1866     {
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));
1871     }
1872
1873   /* Record the FDE associated with this function.  */
1874   current_funcdef_fde = fde_table_in_use;
1875
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;
1883
1884   args_size = old_args_size = 0;
1885 }
1886
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.  */
1890
1891 void
1892 dwarf2out_end_epilogue ()
1893 {
1894   dw_fde_ref fde;
1895   char label[MAX_ARTIFICIAL_LABEL_BYTES];
1896
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);
1903 }
1904
1905 void
1906 dwarf2out_frame_init ()
1907 {
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;
1912
1913   /* Generate the CFA instructions common to all FDE's.  Do it now for the
1914      sake of lookup_cfa.  */
1915
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
1921 }
1922
1923 void
1924 dwarf2out_frame_finish ()
1925 {
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
1937 }  
1938
1939 #endif /* .debug_frame support */
1940
1941 /* And now, the support for symbolic debugging information.  */
1942 #ifdef DWARF2_DEBUGGING_INFO
1943
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.  */
1947
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.  */
1952
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.  */
1956
1957 typedef enum
1958 {
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
1971 }
1972 dw_val_class;
1973
1974 /* Various DIE's use offsets relative to the beginning of the
1975    .debug_info section to refer to each other.  */
1976
1977 typedef long int dw_offset;
1978
1979 /* Define typedefs here to avoid circular dependencies.  */
1980
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;
1989
1990 /* Describe a double word constant value.  */
1991
1992 typedef struct dw_long_long_struct
1993 {
1994   unsigned long hi;
1995   unsigned long low;
1996 }
1997 dw_long_long_const;
1998
1999 /* Describe a floating point constant value.  */
2000
2001 typedef struct dw_fp_struct
2002 {
2003   long *array;
2004   unsigned length;
2005 }
2006 dw_float_const;
2007
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.  */
2012
2013 typedef struct dw_line_info_struct
2014 {
2015   unsigned long dw_file_num;
2016   unsigned long dw_line_num;
2017 }
2018 dw_line_info_entry;
2019
2020 /* Line information for functions in separate sections; each one gets its
2021    own sequence.  */
2022 typedef struct dw_separate_line_info_struct
2023 {
2024   unsigned long dw_file_num;
2025   unsigned long dw_line_num;
2026   unsigned long function;
2027 }
2028 dw_separate_line_info_entry;
2029
2030 /* The dw_val_node describes an attribute's value, as it is
2031    represented internally.  */
2032
2033 typedef struct dw_val_struct
2034 {
2035   dw_val_class val_class;
2036   union
2037     {
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;
2049     }
2050   v;
2051 }
2052 dw_val_node;
2053
2054 /* Locations in memory are described using a sequence of stack machine
2055    operations.  */
2056
2057 typedef struct dw_loc_descr_struct
2058 {
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;
2063 }
2064 dw_loc_descr_node;
2065
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.  */
2069
2070 typedef struct dw_attr_struct
2071 {
2072   enum dwarf_attribute dw_attr;
2073   dw_attr_ref dw_attr_next;
2074   dw_val_node dw_attr_val;
2075 }
2076 dw_attr_node;
2077
2078 /* The Debugging Information Entry (DIE) structure */
2079
2080 typedef struct die_struct
2081 {
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;
2089 }
2090 die_node;
2091
2092 /* The pubname structure */
2093
2094 typedef struct pubname_struct
2095 {
2096   dw_die_ref die;
2097   char * name;
2098 }
2099 pubname_entry;
2100
2101 /* The limbo die list structure.  */
2102 typedef struct limbo_die_struct
2103 {
2104   dw_die_ref die;
2105   struct limbo_die_struct *next;
2106 }
2107 limbo_die_node;
2108
2109 /* How to start an assembler comment.  */
2110 #ifndef ASM_COMMENT_START
2111 #define ASM_COMMENT_START ";#"
2112 #endif
2113
2114 /* Define a macro which returns non-zero for a TYPE_DECL which was
2115    implicitly generated for a tagged type.
2116
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.  */
2123
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)))))))
2134
2135 /* Information concerning the compilation unit's programming
2136    language, and compiler version.  */
2137
2138 extern int flag_traditional;
2139
2140 /* Fixed size portion of the DWARF compilation unit header.  */
2141 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
2142
2143 /* Fixed size portion of debugging line information prolog.  */
2144 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
2145
2146 /* Fixed size portion of public names info.  */
2147 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
2148
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)
2152
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))
2158
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
2163
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.  */
2170
2171 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
2172 #define DWARF_LINE_MIN_INSTR_LENGTH 4
2173 #endif
2174
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
2178
2179 /* First special line opcde - leave room for the standard opcodes.  */
2180 #define DWARF_LINE_OPCODE_BASE  10
2181
2182 /* Range of line offsets in a special line info. opcode.  */
2183 #define DWARF_LINE_RANGE  (254-DWARF_LINE_OPCODE_BASE+1)
2184
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
2190
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;
2194
2195 /* Record the root of the DIE's built for the current compilation unit.  */
2196 static dw_die_ref comp_unit_die;
2197
2198 /* A list of DIEs with a NULL parent waiting to be relocated.  */
2199 static limbo_die_node *limbo_die_list = 0;
2200
2201 /* Pointer to an array of filenames referenced by this compilation unit.  */
2202 static char **file_table;
2203
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;
2208
2209 /* Number of entries in the file_table which are actually in use.  */
2210 static unsigned file_table_in_use;
2211
2212 /* Size (in elements) of increments by which we may expand the filename
2213    table.  */
2214 #define FILE_TABLE_INCREMENT 64
2215
2216 /* Local pointer to the name of the main input file.  Initialized in
2217    dwarf2out_init.  */
2218 static char *primary_filename;
2219
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;
2224
2225 /* Number of elements currently allocated for the decl_die_table.  */
2226 static unsigned decl_die_table_allocated;
2227
2228 /* Number of elements in decl_die_table currently in use.  */
2229 static unsigned decl_die_table_in_use;
2230
2231 /* Size (in elements) of increments by which we may expand the
2232    decl_die_table.  */
2233 #define DECL_DIE_TABLE_INCREMENT 256
2234
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;
2241
2242 /* Number of elements currently allocated for the decl_scope_table.  */
2243 static int decl_scope_table_allocated;
2244
2245 /* Current level of nesting of declaration scopes.  */
2246 static int decl_scope_depth;
2247
2248 /* Size (in elements) of increments by which we may expand the
2249    decl_scope_table.  */
2250 #define DECL_SCOPE_TABLE_INCREMENT 64
2251
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;
2256
2257 /* Number of elements currently allocated for abbrev_die_table.  */
2258 static unsigned abbrev_die_table_allocated;
2259
2260 /* Number of elements in type_die_table currently in use.  */
2261 static unsigned abbrev_die_table_in_use;
2262
2263 /* Size (in elements) of increments by which we may expand the
2264    abbrev_die_table.  */
2265 #define ABBREV_DIE_TABLE_INCREMENT 256
2266
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;
2270
2271 /* Number of elements currently allocated for line_info_table.  */
2272 static unsigned line_info_table_allocated;
2273
2274 /* Number of elements in separate_line_info_table currently in use.  */
2275 static unsigned separate_line_info_table_in_use;
2276
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;
2280
2281 /* Number of elements currently allocated for separate_line_info_table.  */
2282 static unsigned separate_line_info_table_allocated;
2283
2284 /* Number of elements in line_info_table currently in use.  */
2285 static unsigned line_info_table_in_use;
2286
2287 /* Size (in elements) of increments by which we may expand the
2288    line_info_table.  */
2289 #define LINE_INFO_TABLE_INCREMENT 1024
2290
2291 /* A pointer to the base of a table that contains a list of publicly
2292    accessible names.  */
2293 static pubname_ref pubname_table;
2294
2295 /* Number of elements currently allocated for pubname_table.  */
2296 static unsigned pubname_table_allocated;
2297
2298 /* Number of elements in pubname_table currently in use.  */
2299 static unsigned pubname_table_in_use;
2300
2301 /* Size (in elements) of increments by which we may expand the
2302    pubname_table.  */
2303 #define PUBNAME_TABLE_INCREMENT 64
2304
2305 /* A pointer to the base of a table that contains a list of publicly
2306    accessible names.  */
2307 static arange_ref arange_table;
2308
2309 /* Number of elements currently allocated for arange_table.  */
2310 static unsigned arange_table_allocated;
2311
2312 /* Number of elements in arange_table currently in use.  */
2313 static unsigned arange_table_in_use;
2314
2315 /* Size (in elements) of increments by which we may expand the
2316    arange_table.  */
2317 #define ARANGE_TABLE_INCREMENT 64
2318
2319 /* A pointer to the base of a list of incomplete types which might be
2320    completed at some later time.  */
2321
2322 static tree *incomplete_types_list;
2323
2324 /* Number of elements currently allocated for the incomplete_types_list.  */
2325 static unsigned incomplete_types_allocated;
2326
2327 /* Number of elements of incomplete_types_list currently in use.  */
2328 static unsigned incomplete_types;
2329
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
2334
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
2340
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;
2346
2347 /* Forward declarations for functions defined in this file.  */
2348
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));
2536
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
2562
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
2573
2574 /* Labels we insert at beginning sections we can reference instead of
2575    the section names themselves. */
2576
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
2589
2590
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.  */
2596
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];
2602
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
2633 \f
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.  */
2636
2637 static const char *(*demangle_name_func) PARAMS ((const char *));
2638
2639 void
2640 dwarf2out_set_demangle_name_func (func)
2641      const char *(*func) PARAMS ((const char *));
2642 {
2643   demangle_name_func = func;
2644 }
2645 \f
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.  */
2649
2650 static rtx
2651 save_rtx (orig)
2652      register rtx orig;
2653 {
2654   if (ggc_p)
2655     VARRAY_PUSH_RTX (used_rtx_varray, orig);
2656   else
2657     {
2658       push_obstacks_nochange ();
2659       end_temporary_allocation ();
2660       orig = copy_rtx (orig);
2661       pop_obstacks ();
2662     }
2663
2664   return orig;
2665 }
2666
2667 /* Test if rtl node points to a pseudo register.  */
2668
2669 static inline int
2670 is_pseudo_reg (rtl)
2671      register rtx rtl;
2672 {
2673   return (((GET_CODE (rtl) == REG) && (REGNO (rtl) >= FIRST_PSEUDO_REGISTER))
2674           || ((GET_CODE (rtl) == SUBREG)
2675               && (REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER)));
2676 }
2677
2678 /* Return a reference to a type, with its const and volatile qualifiers
2679    removed.  */
2680
2681 static inline tree
2682 type_main_variant (type)
2683      register tree type;
2684 {
2685   type = TYPE_MAIN_VARIANT (type);
2686
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.  */
2691
2692   if (TREE_CODE (type) == ARRAY_TYPE)
2693     while (type != TYPE_MAIN_VARIANT (type))
2694       type = TYPE_MAIN_VARIANT (type);
2695
2696   return type;
2697 }
2698
2699 /* Return non-zero if the given type node represents a tagged type.  */
2700
2701 static inline int
2702 is_tagged_type (type)
2703      register tree type;
2704 {
2705   register enum tree_code code = TREE_CODE (type);
2706
2707   return (code == RECORD_TYPE || code == UNION_TYPE
2708           || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
2709 }
2710
2711 /* Convert a DIE tag into its string name.  */
2712
2713 static const char *
2714 dwarf_tag_name (tag)
2715      register unsigned tag;
2716 {
2717   switch (tag)
2718     {
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>";
2825     }
2826 }
2827
2828 /* Convert a DWARF attribute code into its string name.  */
2829
2830 static const char *
2831 dwarf_attr_name (attr)
2832      register unsigned attr;
2833 {
2834   switch (attr)
2835     {
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";
2960
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";
2983
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>";
2998     }
2999 }
3000
3001 /* Convert a DWARF value form code into its string name.  */
3002
3003 static const char *
3004 dwarf_form_name (form)
3005      register unsigned form;
3006 {
3007   switch (form)
3008     {
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>";
3053     }
3054 }
3055
3056 /* Convert a DWARF stack opcode into its string name.  */
3057
3058 static const char *
3059 dwarf_stack_op_name (op)
3060      register unsigned op;
3061 {
3062   switch (op)
3063     {
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>";
3356     }
3357 }
3358
3359 /* Convert a DWARF type code into its string name.  */
3360
3361 #if 0
3362 static const char *
3363 dwarf_type_encoding_name (enc)
3364      register unsigned enc;
3365 {
3366   switch (enc)
3367     {
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>";
3386     }
3387 }
3388 #endif
3389 \f
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.  */
3395
3396 static tree
3397 decl_ultimate_origin (decl)
3398      register tree decl;
3399 {
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;
3405
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
3412
3413   return DECL_ABSTRACT_ORIGIN (decl);
3414 }
3415
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.  */
3421
3422 static tree
3423 block_ultimate_origin (block)
3424      register tree block;
3425 {
3426   register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
3427
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;
3433
3434   if (immediate_origin == NULL_TREE)
3435     return NULL_TREE;
3436   else
3437     {
3438       register tree ret_val;
3439       register tree lookahead = immediate_origin;
3440
3441       do
3442         {
3443           ret_val = lookahead;
3444           lookahead = (TREE_CODE (ret_val) == BLOCK)
3445             ? BLOCK_ABSTRACT_ORIGIN (ret_val)
3446             : NULL;
3447         }
3448       while (lookahead != NULL && lookahead != ret_val);
3449
3450       return ret_val;
3451     }
3452 }
3453
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.  */
3457
3458 static tree
3459 decl_class_context (decl)
3460      tree decl;
3461 {
3462   tree context = NULL_TREE;
3463
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)))));
3469
3470   if (context && TREE_CODE_CLASS (TREE_CODE (context)) != 't')
3471     context = NULL_TREE;
3472
3473   return context;
3474 }
3475 \f
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.  */
3478
3479 static inline void
3480 add_dwarf_attr (die, attr)
3481      register dw_die_ref die;
3482      register dw_attr_ref attr;
3483 {
3484   if (die != NULL && attr != NULL)
3485     {
3486       attr->dw_attr_next = die->die_attr;
3487       die->die_attr = attr;
3488     }
3489 }
3490
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;
3495 {
3496   return a->dw_attr_val.val_class;
3497 }
3498
3499 /* Add a flag value attribute to a DIE.  */
3500
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;
3506 {
3507   register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3508
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);
3514 }
3515
3516 static inline unsigned AT_flag PARAMS ((dw_attr_ref));
3517 static inline unsigned
3518 AT_flag (a)
3519      register dw_attr_ref a;
3520 {
3521   if (a && AT_class (a) == dw_val_class_flag)
3522     return a->dw_attr_val.v.val_flag;
3523
3524   return 0;
3525 }
3526
3527 /* Add a signed integer attribute value to a DIE.  */
3528
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;
3534 {
3535   register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3536
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);
3542 }
3543
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;
3548 {
3549   if (a && AT_class (a) == dw_val_class_const)
3550     return a->dw_attr_val.v.val_int;
3551
3552   return 0;
3553 }
3554
3555 /* Add an unsigned integer attribute value to a DIE.  */
3556
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;
3562 {
3563   register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3564
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);
3570 }
3571
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;
3576 {
3577   if (a && AT_class (a) == dw_val_class_unsigned_const)
3578     return a->dw_attr_val.v.val_unsigned;
3579
3580   return 0;
3581 }
3582
3583 /* Add an unsigned double integer attribute value to a DIE.  */
3584
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;
3591 {
3592   register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3593
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);
3600 }
3601
3602 /* Add a floating point attribute value to a DIE and return it.  */
3603
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;
3610 {
3611   register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3612
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);
3619 }
3620
3621 /* Add a string attribute value to a DIE.  */
3622
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;
3628 {
3629   register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3630
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);
3636 }
3637
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;
3642 {
3643   if (a && AT_class (a) == dw_val_class_str)
3644     return a->dw_attr_val.v.val_str;
3645
3646   return NULL;
3647 }
3648
3649 /* Add a DIE reference attribute value to a DIE.  */
3650
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;
3656 {
3657   register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3658
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);
3664 }
3665
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;
3670 {
3671   if (a && AT_class (a) == dw_val_class_die_ref)
3672     return a->dw_attr_val.v.val_die_ref;
3673
3674   return NULL;
3675 }
3676
3677 /* Add an FDE reference attribute value to a DIE.  */
3678
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;
3684 {
3685   register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3686
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);
3692 }
3693
3694 /* Add a location description attribute value to a DIE.  */
3695
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;
3701 {
3702   register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3703
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);
3709 }
3710
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;
3715 {
3716   if (a && AT_class (a) == dw_val_class_loc)
3717     return a->dw_attr_val.v.val_loc;
3718
3719   return NULL;
3720 }
3721
3722 /* Add an address constant attribute value to a DIE.  */
3723
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;
3729 {
3730   register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3731
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);
3737 }
3738
3739 static inline rtx AT_addr PARAMS ((dw_attr_ref));
3740 static inline rtx
3741 AT_addr (a)
3742      register dw_attr_ref a;
3743 {
3744   if (a && AT_class (a) == dw_val_class_addr)
3745     return a->dw_attr_val.v.val_addr;
3746
3747   return NULL;
3748 }
3749
3750 /* Add a label identifier attribute value to a DIE.  */
3751
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;
3757 {
3758   register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3759
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);
3765 }
3766
3767 /* Add a section offset attribute value to a DIE.  */
3768
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;
3774 {
3775   register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3776
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);
3782   
3783 }
3784
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;
3789 {
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;
3793
3794   return NULL;
3795 }
3796
3797 /* Get the attribute of type attr_kind.  */
3798
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;
3803 {
3804   register dw_attr_ref a;
3805   register dw_die_ref spec = NULL;
3806   
3807   if (die != NULL)
3808     {
3809       for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
3810         {
3811           if (a->dw_attr == attr_kind)
3812             return a;
3813
3814           if (a->dw_attr == DW_AT_specification
3815               || a->dw_attr == DW_AT_abstract_origin)
3816             spec = AT_ref (a);
3817         }
3818
3819       if (spec)
3820         return get_AT (spec, attr_kind);
3821     }
3822
3823   return NULL;
3824 }
3825
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.  */
3830
3831 static inline const char *
3832 get_AT_low_pc (die)
3833      register dw_die_ref die;
3834 {
3835   register dw_attr_ref a = get_AT (die, DW_AT_low_pc);
3836   return AT_lbl (a);
3837 }
3838
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.  */
3843
3844 static inline const char *
3845 get_AT_hi_pc (die)
3846      register dw_die_ref die;
3847 {
3848   register dw_attr_ref a = get_AT (die, DW_AT_high_pc);
3849   return AT_lbl (a);
3850 }
3851
3852 /* Return the value of the string attribute designated by ATTR_KIND, or
3853    NULL if it is not present.  */
3854
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;
3859 {
3860   register dw_attr_ref a = get_AT (die, attr_kind);
3861   return AT_string (a);
3862 }
3863
3864 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
3865    if it is not present.  */
3866
3867 static inline int
3868 get_AT_flag (die, attr_kind)
3869      register dw_die_ref die;
3870      register enum dwarf_attribute attr_kind;
3871 {
3872   register dw_attr_ref a = get_AT (die, attr_kind);
3873   return AT_flag (a);
3874 }
3875
3876 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
3877    if it is not present.  */
3878
3879 static inline unsigned
3880 get_AT_unsigned (die, attr_kind)
3881      register dw_die_ref die;
3882      register enum dwarf_attribute attr_kind;
3883 {
3884   register dw_attr_ref a = get_AT (die, attr_kind);
3885   return AT_unsigned (a);
3886 }
3887
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;
3892 {
3893   register dw_attr_ref a = get_AT (die, attr_kind);
3894   return AT_ref (a);
3895 }
3896
3897 static inline int
3898 is_c_family ()
3899 {
3900   register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
3901
3902   return (lang == DW_LANG_C || lang == DW_LANG_C89
3903           || lang == DW_LANG_C_plus_plus);
3904
3905
3906 static inline int
3907 is_fortran ()
3908 {
3909   register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
3910
3911   return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
3912
3913
3914 /* Free up the memory used by A.  */
3915
3916 static inline void free_AT PARAMS ((dw_attr_ref));
3917 static inline void
3918 free_AT (a)
3919      dw_attr_ref a;
3920 {
3921   switch (AT_class (a))
3922     {
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;
3928
3929     default:
3930       break;
3931     }
3932
3933   free (a);
3934 }  
3935
3936 /* Remove the specified attribute if present.  */
3937
3938 static void
3939 remove_AT (die, attr_kind)
3940      register dw_die_ref die;
3941      register enum dwarf_attribute attr_kind;
3942 {
3943   register dw_attr_ref *p;
3944   register dw_attr_ref removed = NULL;
3945
3946   if (die != NULL)
3947     {
3948       for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next))
3949         if ((*p)->dw_attr == attr_kind)
3950           {
3951             removed = *p;
3952             *p = (*p)->dw_attr_next;
3953             break;
3954           }
3955
3956       if (removed != 0)
3957         free_AT (removed);
3958     }
3959 }
3960
3961 /* Free up the memory used by DIE.  */
3962
3963 static inline void free_die PARAMS ((dw_die_ref));
3964 static inline void
3965 free_die (die)
3966      dw_die_ref die;
3967 {
3968   remove_children (die);
3969   free (die);
3970 }
3971
3972 /* Discard the children of this DIE.  */
3973
3974 static void
3975 remove_children (die)
3976      register dw_die_ref die;
3977 {
3978   register dw_die_ref child_die = die->die_child;
3979
3980   die->die_child = NULL;
3981
3982   while (child_die != NULL)
3983     {
3984       register dw_die_ref tmp_die = child_die;
3985       register dw_attr_ref a;
3986
3987       child_die = child_die->die_sib;
3988       
3989       for (a = tmp_die->die_attr; a != NULL; )
3990         {
3991           register dw_attr_ref tmp_a = a;
3992
3993           a = a->dw_attr_next;
3994           free_AT (tmp_a);
3995         }
3996
3997       free_die (tmp_die);
3998     }
3999 }
4000
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.  */
4003
4004 static inline void
4005 add_child_die (die, child_die)
4006      register dw_die_ref die;
4007      register dw_die_ref child_die;
4008 {
4009   if (die != NULL && child_die != NULL)
4010     {
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;
4016     }
4017 }
4018
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.  */
4021
4022 static void
4023 splice_child_die (parent, child)
4024      dw_die_ref parent, child;
4025 {
4026   dw_die_ref *p;
4027
4028   /* We want the declaration DIE from inside the class, not the
4029      specification DIE at toplevel.  */
4030   if (child->die_parent != parent)
4031     {
4032       dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
4033       if (tmp)
4034         child = tmp;
4035     }
4036
4037   if (child->die_parent != parent
4038       && child->die_parent != get_AT_ref (parent, DW_AT_specification))
4039     abort ();
4040
4041   for (p = &(parent->die_child); *p; p = &((*p)->die_sib))
4042     if (*p == child)
4043       {
4044         *p = child->die_sib;
4045         break;
4046       }
4047
4048   child->die_sib = parent->die_child;
4049   parent->die_child = child;
4050 }
4051
4052 /* Return a pointer to a newly created DIE node.  */
4053
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;
4058 {
4059   register dw_die_ref die = (dw_die_ref) xmalloc (sizeof (die_node));
4060
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;
4068
4069   if (parent_die != NULL)
4070     add_child_die (parent_die, die);
4071   else
4072     {
4073       limbo_die_node *limbo_node;
4074
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;
4079     }
4080
4081   return die;
4082 }
4083
4084 /* Return the DIE associated with the given type specifier.  */
4085
4086 static inline dw_die_ref
4087 lookup_type_die (type)
4088      register tree type;
4089 {
4090   return (dw_die_ref) TYPE_SYMTAB_POINTER (type);
4091 }
4092
4093 /* Equate a DIE to a given type specifier.  */
4094
4095 static inline void
4096 equate_type_number_to_die (type, type_die)
4097      register tree type;
4098      register dw_die_ref type_die;
4099 {
4100   TYPE_SYMTAB_POINTER (type) = (char *) type_die;
4101 }
4102
4103 /* Return the DIE associated with a given declaration.  */
4104
4105 static inline dw_die_ref
4106 lookup_decl_die (decl)
4107      register tree decl;
4108 {
4109   register unsigned decl_id = DECL_UID (decl);
4110
4111   return (decl_id < decl_die_table_in_use
4112           ? decl_die_table[decl_id] : NULL);
4113 }
4114
4115 /* Equate a DIE to a particular declaration.  */
4116
4117 static void
4118 equate_decl_number_to_die (decl, decl_die)
4119      register tree decl;
4120      register dw_die_ref decl_die;
4121 {
4122   register unsigned decl_id = DECL_UID (decl);
4123   register unsigned num_allocated;
4124
4125   if (decl_id >= decl_die_table_allocated)
4126     {
4127       num_allocated
4128         = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
4129            / DECL_DIE_TABLE_INCREMENT)
4130           * DECL_DIE_TABLE_INCREMENT;
4131
4132       decl_die_table
4133         = (dw_die_ref *) xrealloc (decl_die_table,
4134                                    sizeof (dw_die_ref) * num_allocated);
4135
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;
4139     }
4140
4141   if (decl_id >= decl_die_table_in_use)
4142     decl_die_table_in_use = (decl_id + 1);
4143
4144   decl_die_table[decl_id] = decl_die;
4145 }
4146
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.  */
4150
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;
4156 {
4157   register dw_loc_descr_ref descr
4158     = (dw_loc_descr_ref) xmalloc (sizeof (dw_loc_descr_node));
4159
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;
4166
4167   return descr;
4168 }
4169
4170 /* Add a location description term to a location description expression.  */
4171
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;
4176 {
4177   register dw_loc_descr_ref *d;
4178
4179   /* Find the end of the chain.  */
4180   for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
4181     ;
4182
4183   *d = descr;
4184 }
4185 \f
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;
4190
4191 /* Indent the line the number of spaces given by print_indent.  */
4192
4193 static inline void
4194 print_spaces (outfile)
4195      FILE *outfile;
4196 {
4197   fprintf (outfile, "%*s", print_indent, "");
4198 }
4199
4200 /* Print the information associated with a given DIE, and its children.
4201    This routine is a debugging aid only.  */
4202
4203 static void
4204 print_die (die, outfile)
4205      dw_die_ref die;
4206      FILE *outfile;
4207 {
4208   register dw_attr_ref a;
4209   register dw_die_ref c;
4210
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);
4217
4218   for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4219     {
4220       print_spaces (outfile);
4221       fprintf (outfile, "  %s: ", dwarf_attr_name (a->dw_attr));
4222
4223       switch (AT_class (a))
4224         {
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;
4266         }
4267
4268       fprintf (outfile, "\n");
4269     }
4270
4271   if (die->die_child != NULL)
4272     {
4273       print_indent += 4;
4274       for (c = die->die_child; c != NULL; c = c->die_sib)
4275         print_die (c, outfile);
4276
4277       print_indent -= 4;
4278     }
4279 }
4280
4281 /* Print the contents of the source code line number correspondence table.
4282    This routine is a debugging aid only.  */
4283
4284 static void
4285 print_dwarf_line_table (outfile)
4286      FILE *outfile;
4287 {
4288   register unsigned i;
4289   register dw_line_info_ref line_info;
4290
4291   fprintf (outfile, "\n\nDWARF source line information\n");
4292   for (i = 1; i < line_info_table_in_use; ++i)
4293     {
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");
4299     }
4300
4301   fprintf (outfile, "\n\n");
4302 }
4303
4304 /* Print the information collected for a given DIE.  */
4305
4306 void
4307 debug_dwarf_die (die)
4308      dw_die_ref die;
4309 {
4310   print_die (die, stderr);
4311 }
4312
4313 /* Print all DWARF information collected for the compilation unit.
4314    This routine is a debugging aid only.  */
4315
4316 void
4317 debug_dwarf ()
4318 {
4319   print_indent = 0;
4320   print_die (comp_unit_die, stderr);
4321   if (! DWARF2_ASM_LINE_DEBUG_INFO)
4322     print_dwarf_line_table (stderr);
4323 }
4324 \f
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.  */
4328
4329 static void
4330 reverse_die_lists (die)
4331      register dw_die_ref die;
4332 {
4333   register dw_die_ref c, cp, cn;
4334   register dw_attr_ref a, ap, an;
4335
4336   for (a = die->die_attr, ap = 0; a; a = an)
4337     {
4338       an = a->dw_attr_next;
4339       a->dw_attr_next = ap;
4340       ap = a;
4341     }
4342   die->die_attr = ap;
4343
4344   for (c = die->die_child, cp = 0; c; c = cn)
4345     {
4346       cn = c->die_sib;
4347       c->die_sib = cp;
4348       cp = c;
4349     }
4350   die->die_child = cp;
4351 }
4352
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.  */
4357
4358 static void
4359 add_sibling_attributes (die)
4360      register dw_die_ref die;
4361 {
4362   register dw_die_ref c;
4363
4364   reverse_die_lists (die);
4365
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);
4369
4370   for (c = die->die_child; c != NULL; c = c->die_sib)
4371     add_sibling_attributes (c);
4372 }
4373
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.  */
4379
4380 static void
4381 build_abbrev_table (die)
4382      register dw_die_ref die;
4383 {
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)
4389     {
4390       register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
4391
4392       if (abbrev->die_tag == die->die_tag)
4393         {
4394           if ((abbrev->die_child != NULL) == (die->die_child != NULL))
4395             {
4396               a_attr = abbrev->die_attr;
4397               d_attr = die->die_attr;
4398
4399               while (a_attr != NULL && d_attr != NULL)
4400                 {
4401                   if ((a_attr->dw_attr != d_attr->dw_attr)
4402                       || (value_format (a_attr) != value_format (d_attr)))
4403                     break;
4404
4405                   a_attr = a_attr->dw_attr_next;
4406                   d_attr = d_attr->dw_attr_next;
4407                 }
4408
4409               if (a_attr == NULL && d_attr == NULL)
4410                 break;
4411             }
4412         }
4413     }
4414
4415   if (abbrev_id >= abbrev_die_table_in_use)
4416     {
4417       if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
4418         {
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);
4423
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;
4427         }
4428
4429       ++abbrev_die_table_in_use;
4430       abbrev_die_table[abbrev_id] = die;
4431     }
4432
4433   die->die_abbrev = abbrev_id;
4434   for (c = die->die_child; c != NULL; c = c->die_sib)
4435     build_abbrev_table (c);
4436 }
4437 \f
4438 /* Return the size of a string, including the null byte.
4439
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.  */
4444
4445 static unsigned long
4446 size_of_string (str)
4447      register const char *str;
4448 {
4449   return strlen (str) + 1;
4450 }
4451
4452 /* Return the size of a location descriptor.  */
4453
4454 static unsigned long
4455 size_of_loc_descr (loc)
4456      register dw_loc_descr_ref loc;
4457 {
4458   register unsigned long size = 1;
4459
4460   switch (loc->dw_loc_opc)
4461     {
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;
4550     }
4551
4552   return size;
4553 }
4554
4555 /* Return the size of a series of location descriptors.  */
4556
4557 static unsigned long
4558 size_of_locs (loc)
4559      register dw_loc_descr_ref loc;
4560 {
4561   register unsigned long size = 0;
4562
4563   for (; loc != NULL; loc = loc->dw_loc_next)
4564     size += size_of_loc_descr (loc);
4565
4566   return size;
4567 }
4568
4569 /* Return the power-of-two number of bytes necessary to represent VALUE.  */
4570
4571 static int
4572 constant_size (value)
4573      long unsigned value;
4574 {
4575   int log;
4576
4577   if (value == 0)
4578     log = 0;
4579   else
4580     log = floor_log2 (value);
4581
4582   log = log / 8;
4583   log = 1 << (floor_log2 (log) + 1);
4584
4585   return log;
4586 }
4587
4588 /* Return the size of a DIE, as it is represented in the
4589    .debug_info section.  */
4590
4591 static unsigned long
4592 size_of_die (die)
4593      register dw_die_ref die;
4594 {
4595   register unsigned long size = 0;
4596   register dw_attr_ref a;
4597
4598   size += size_of_uleb128 (die->die_abbrev);
4599   for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4600     {
4601       switch (AT_class (a))
4602         {
4603         case dw_val_class_addr:
4604           size += PTR_SIZE;
4605           break;
4606         case dw_val_class_loc:
4607           {
4608             register unsigned long lsize = size_of_locs (AT_loc (a));
4609
4610             /* Block length.  */
4611             size += constant_size (lsize);
4612             size += lsize;
4613           }
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 ();
4647         }
4648     }
4649
4650   return size;
4651 }
4652
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.  */
4658
4659 static void
4660 calc_die_sizes (die)
4661      dw_die_ref die;
4662 {
4663   register dw_die_ref c;
4664   die->die_offset = next_die_offset;
4665   next_die_offset += size_of_die (die);
4666
4667   for (c = die->die_child; c != NULL; c = c->die_sib)
4668     calc_die_sizes (c);
4669
4670   if (die->die_child != NULL)
4671     /* Count the null byte used to terminate sibling lists.  */
4672     next_die_offset += 1;
4673 }
4674
4675 /* Return the size of the line information prolog generated for the
4676    compilation unit.  */
4677
4678 static unsigned long
4679 size_of_line_prolog ()
4680 {
4681   register unsigned long size;
4682   register unsigned long ft_index;
4683
4684   size = DWARF_LINE_PROLOG_HEADER_SIZE;
4685
4686   /* Count the size of the table giving number of args for each
4687      standard opcode.  */
4688   size += DWARF_LINE_OPCODE_BASE - 1;
4689
4690   /* Include directory table is empty (at present).  Count only the
4691      null byte used to terminate the table.  */
4692   size += 1;
4693
4694   for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
4695     {
4696       /* File name entry.  */
4697       size += size_of_string (file_table[ft_index]);
4698
4699       /* Include directory index.  */
4700       size += size_of_uleb128 (0);
4701
4702       /* Modification time.  */
4703       size += size_of_uleb128 (0);
4704
4705       /* File length in bytes.  */
4706       size += size_of_uleb128 (0);
4707     }
4708
4709   /* Count the file table terminator.  */
4710   size += 1;
4711   return size;
4712 }
4713
4714 /* Return the size of the .debug_pubnames table  generated for the
4715    compilation unit.  */
4716
4717 static unsigned long
4718 size_of_pubnames ()
4719 {
4720   register unsigned long size;
4721   register unsigned i;
4722
4723   size = DWARF_PUBNAMES_HEADER_SIZE;
4724   for (i = 0; i < pubname_table_in_use; ++i)
4725     {
4726       register pubname_ref p = &pubname_table[i];
4727       size += DWARF_OFFSET_SIZE + size_of_string (p->name);
4728     }
4729
4730   size += DWARF_OFFSET_SIZE;
4731   return size;
4732 }
4733
4734 /* Return the size of the information in the .debug_aranges section.  */
4735
4736 static unsigned long
4737 size_of_aranges ()
4738 {
4739   register unsigned long size;
4740
4741   size = DWARF_ARANGES_HEADER_SIZE;
4742
4743   /* Count the address/length pair for this compilation unit.  */
4744   size += 2 * PTR_SIZE;
4745   size += 2 * PTR_SIZE * arange_table_in_use;
4746
4747   /* Count the two zero words used to terminated the address range table.  */
4748   size += 2 * PTR_SIZE;
4749   return size;
4750 }
4751 \f
4752 /* Select the encoding of an attribute value.  */
4753
4754 static enum dwarf_form
4755 value_format (a)
4756      dw_attr_ref a;
4757 {
4758   switch (a->dw_attr_val.val_class)
4759     {
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))))
4764         {
4765         case 1:
4766           return DW_FORM_block1;
4767         case 2:
4768           return DW_FORM_block2;
4769         default:
4770           abort ();
4771         }
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)))
4776         {
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 ();
4787         }
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 ();
4806     }
4807 }
4808
4809 /* Output the encoding of an attribute value.  */
4810
4811 static void
4812 output_value_format (a)
4813      dw_attr_ref a;
4814 {
4815   enum dwarf_form form = value_format (a);
4816
4817   output_uleb128 (form);
4818   if (flag_debug_asm)
4819     fprintf (asm_out_file, " (%s)", dwarf_form_name (form));
4820
4821   fputc ('\n', asm_out_file);
4822 }
4823
4824 /* Output the .debug_abbrev section which defines the DIE abbreviation
4825    table.  */
4826
4827 static void
4828 output_abbrev_section ()
4829 {
4830   unsigned long abbrev_id;
4831
4832   dw_attr_ref a_attr;
4833   for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
4834     {
4835       register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
4836
4837       output_uleb128 (abbrev_id);
4838       if (flag_debug_asm)
4839         fprintf (asm_out_file, " (abbrev code)");
4840
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));
4846
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);
4850
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"));
4856
4857       fputc ('\n', asm_out_file);
4858
4859       for (a_attr = abbrev->die_attr; a_attr != NULL;
4860            a_attr = a_attr->dw_attr_next)
4861         {
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));
4866
4867           fputc ('\n', asm_out_file);
4868           output_value_format (a_attr);
4869         }
4870
4871       fprintf (asm_out_file, "\t%s\t0,0\n", ASM_BYTE_OP);
4872     }
4873
4874   /* Terminate the table.  */
4875   fprintf (asm_out_file, "\t%s\t0\n", ASM_BYTE_OP);
4876 }
4877
4878 /* Output location description stack opcode's operands (if any).  */
4879
4880 static void
4881 output_loc_operands (loc)
4882      register dw_loc_descr_ref loc;
4883 {
4884   register dw_val_ref val1 = &loc->dw_loc_oprnd1;
4885   register dw_val_ref val2 = &loc->dw_loc_oprnd2;
4886
4887   switch (loc->dw_loc_opc)
4888     {
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;
4994     }
4995 }
4996
4997 /* Output the DIE and its attributes.  Called recursively to generate
4998    the definitions of each child DIE.  */
4999
5000 static void
5001 output_die (die)
5002      register dw_die_ref die;
5003 {
5004   register dw_attr_ref a;
5005   register dw_die_ref c;
5006   register unsigned long size;
5007   register dw_loc_descr_ref loc;
5008
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));
5013
5014   fputc ('\n', asm_out_file);
5015
5016   for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5017     {
5018       switch (AT_class (a))
5019         {
5020         case dw_val_class_addr:
5021           ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, AT_addr (a));
5022           break;
5023
5024         case dw_val_class_loc:
5025           size = size_of_locs (AT_loc (a));
5026
5027           /* Output the block length for this list of location operations.  */
5028           switch (constant_size (size))
5029             {
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 ();
5038             }
5039
5040           if (flag_debug_asm)
5041             fprintf (asm_out_file, "\t%s %s",
5042                      ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5043
5044           fputc ('\n', asm_out_file);
5045           for (loc = AT_loc (a); loc != NULL; loc = loc->dw_loc_next)
5046             {
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));
5052
5053               fputc ('\n', asm_out_file);
5054
5055               /* Output the operand(s) (if any).  */
5056               output_loc_operands (loc);
5057             }
5058           break;
5059
5060         case dw_val_class_const:
5061           ASM_OUTPUT_DWARF_DATA4 (asm_out_file, AT_int (a));
5062           break;
5063
5064         case dw_val_class_unsigned_const:
5065           switch (constant_size (AT_unsigned (a)))
5066             {
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 ();
5083             }
5084           break;
5085
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));
5091
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);
5096
5097           if (flag_debug_asm)
5098             fprintf (asm_out_file,
5099                      "\t%s long long constant", ASM_COMMENT_START);
5100           
5101           fputc ('\n', asm_out_file);
5102           break;
5103
5104         case dw_val_class_float:
5105           {
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));
5112
5113             fputc ('\n', asm_out_file);
5114             for (i = 0; i < a->dw_attr_val.v.val_float.length; ++i)
5115               {
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);
5121
5122                 fputc ('\n', asm_out_file);
5123               }
5124           break;
5125           }
5126
5127         case dw_val_class_flag:
5128           ASM_OUTPUT_DWARF_DATA1 (asm_out_file, AT_flag (a));
5129           break;
5130
5131         case dw_val_class_die_ref:
5132           ASM_OUTPUT_DWARF_DATA (asm_out_file, AT_ref (a)->die_offset);
5133           break;
5134
5135         case dw_val_class_fde_ref:
5136           {
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);
5142           }
5143           break;
5144
5145         case dw_val_class_lbl_id:
5146           ASM_OUTPUT_DWARF_ADDR (asm_out_file, AT_lbl (a));
5147           break;
5148
5149         case dw_val_class_lbl_offset:
5150           ASM_OUTPUT_DWARF_OFFSET (asm_out_file, AT_lbl (a));
5151           break;
5152
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;
5160
5161         default:
5162           abort ();
5163         }
5164
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)
5168         {
5169           if (flag_debug_asm)
5170             fprintf (asm_out_file, "\t%s %s",
5171                      ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5172
5173           fputc ('\n', asm_out_file);
5174         }
5175     }
5176
5177   for (c = die->die_child; c != NULL; c = c->die_sib)
5178     output_die (c);
5179
5180   if (die->die_child != NULL)
5181     {
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);
5187
5188       fputc ('\n', asm_out_file);
5189     }
5190 }
5191
5192 /* Output the compilation unit that appears at the beginning of the
5193    .debug_info section, and precedes the DIE descriptions.  */
5194
5195 static void
5196 output_compilation_unit_header ()
5197 {
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);
5202
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);
5207
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);
5213
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);
5218
5219   fputc ('\n', asm_out_file);
5220 }
5221
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.  */
5225
5226 static const char *
5227 dwarf2_name (decl, scope)
5228      tree decl;
5229      int scope;
5230 {
5231   return (*decl_printable_name) (decl, scope ? 1 : 0);
5232 }
5233
5234 /* Add a new entry to .debug_pubnames if appropriate.  */
5235
5236 static void
5237 add_pubname (decl, die)
5238      tree decl;
5239      dw_die_ref die;
5240 {
5241   pubname_ref p;
5242
5243   if (! TREE_PUBLIC (decl))
5244     return;
5245
5246   if (pubname_table_in_use == pubname_table_allocated)
5247     {
5248       pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
5249       pubname_table = (pubname_ref) xrealloc
5250         (pubname_table, pubname_table_allocated * sizeof (pubname_entry));
5251     }
5252
5253   p = &pubname_table[pubname_table_in_use++];
5254   p->die = die;
5255
5256   p->name = xstrdup (dwarf2_name (decl, 1));
5257 }
5258
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.  */
5262
5263 static void
5264 output_pubnames ()
5265 {
5266   register unsigned i;
5267   register unsigned long pubnames_length = size_of_pubnames ();
5268
5269   ASM_OUTPUT_DWARF_DATA (asm_out_file, pubnames_length);
5270
5271   if (flag_debug_asm)
5272     fprintf (asm_out_file, "\t%s Length of Public Names Info.",
5273              ASM_COMMENT_START);
5274
5275   fputc ('\n', asm_out_file);
5276   ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
5277
5278   if (flag_debug_asm)
5279     fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
5280
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);
5286
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);
5291
5292   fputc ('\n', asm_out_file);
5293   for (i = 0; i < pubname_table_in_use; ++i)
5294     {
5295       register pubname_ref pub = &pubname_table[i];
5296
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);
5300
5301       fputc ('\n', asm_out_file);
5302
5303       if (flag_debug_asm)
5304         {
5305           ASM_OUTPUT_DWARF_STRING (asm_out_file, pub->name);
5306           fprintf (asm_out_file, "%s external name", ASM_COMMENT_START);
5307         }
5308       else
5309         {
5310           ASM_OUTPUT_ASCII (asm_out_file, pub->name,
5311                             (int) strlen (pub->name) + 1);
5312         }
5313
5314       fputc ('\n', asm_out_file);
5315     }
5316
5317   ASM_OUTPUT_DWARF_DATA (asm_out_file, 0);
5318   fputc ('\n', asm_out_file);
5319 }
5320
5321 /* Add a new entry to .debug_aranges if appropriate.  */
5322
5323 static void
5324 add_arange (decl, die)
5325      tree decl;
5326      dw_die_ref die;
5327 {
5328   if (! DECL_SECTION_NAME (decl))
5329     return;
5330
5331   if (arange_table_in_use == arange_table_allocated)
5332     {
5333       arange_table_allocated += ARANGE_TABLE_INCREMENT;
5334       arange_table
5335         = (arange_ref) xrealloc (arange_table,
5336                                  arange_table_allocated * sizeof (dw_die_ref));
5337     }
5338
5339   arange_table[arange_table_in_use++] = die;
5340 }
5341
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.  */
5345
5346 static void
5347 output_aranges ()
5348 {
5349   register unsigned i;
5350   register unsigned long aranges_length = size_of_aranges ();
5351
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);
5356
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);
5361
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);
5367
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);
5372
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);
5378
5379   fputc ('\n', asm_out_file);
5380
5381   /* We need to align to twice the pointer size here.  */
5382   if (DWARF_ARANGES_PAD_SIZE)
5383     {
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);
5392     }
5393
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);
5398
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);
5404
5405   fputc ('\n', asm_out_file);
5406   for (i = 0; i < arange_table_in_use; ++i)
5407     {
5408       dw_die_ref die = arange_table[i];
5409
5410       if (die->die_tag == DW_TAG_subprogram)
5411         ASM_OUTPUT_DWARF_ADDR (asm_out_file, get_AT_low_pc (die));
5412       else
5413         {
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).  */
5417
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 ();
5422
5423           loc = AT_loc (a);
5424           if (loc->dw_loc_opc != DW_OP_addr)
5425             abort ();
5426
5427           ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file,
5428                                        loc->dw_loc_oprnd1.v.val_addr);
5429         }
5430
5431       if (flag_debug_asm)
5432         fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
5433
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));
5441
5442       if (flag_debug_asm)
5443         fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
5444
5445       fputc ('\n', asm_out_file);
5446     }
5447
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);
5453 }
5454
5455 /* Output the source line number correspondence information.  This
5456    information goes into the .debug_line section.  */
5457
5458 static void
5459 output_line_info ()
5460 {
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;
5472
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);
5477
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);
5483
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);
5488
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);
5494
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);
5500
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);
5506
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);
5512
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);
5517
5518   fputc ('\n', asm_out_file);
5519   for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc)
5520     {
5521       switch (opc)
5522         {
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;
5533         }
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);
5539     }
5540
5541   if (flag_debug_asm)
5542     fprintf (asm_out_file, "%s Include Directory Table\n", ASM_COMMENT_START);
5543
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);
5549
5550   for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
5551     {
5552       if (flag_debug_asm)
5553         {
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);
5557         }
5558       else
5559         {
5560           ASM_OUTPUT_ASCII (asm_out_file,
5561                             file_table[ft_index],
5562                             (int) strlen (file_table[ft_index]) + 1);
5563         }
5564
5565       fputc ('\n', asm_out_file);
5566
5567       /* Include directory index */
5568       output_uleb128 (0);
5569       fputc ('\n', asm_out_file);
5570
5571       /* Modification time */
5572       output_uleb128 (0);
5573       fputc ('\n', asm_out_file);
5574
5575       /* File length in bytes */
5576       output_uleb128 (0);
5577       fputc ('\n', asm_out_file);
5578     }
5579
5580   /* Terminate the file name table */
5581   ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5582   fputc ('\n', asm_out_file);
5583
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.  */
5587
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)
5594     {
5595       register dw_line_info_ref line_info = &line_info_table[lt_index];
5596
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.  */
5601
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
5609
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)
5622         {
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);
5628
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);
5632         }
5633       else
5634         {
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);
5647         }
5648       strcpy (prev_line_label, line_label);
5649
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)
5653         {
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);
5658
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]);
5663
5664           fputc ('\n', asm_out_file);
5665         }
5666
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)
5670         {
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))
5675             {
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);
5684
5685               fputc ('\n', asm_out_file);
5686             }
5687           else
5688             {
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);
5695
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);
5703             }
5704         }
5705       else
5706         {
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);
5712         }
5713     }
5714
5715   /* Emit debug info for the address of the end of the function.  */
5716   if (0)
5717     {
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);
5722
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);
5726     }
5727   else
5728     {
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);
5739     }
5740
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);
5744
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);
5750
5751   function = 0;
5752   current_file = 1;
5753   current_line = 1;
5754   for (lt_index = 0; lt_index < separate_line_info_table_in_use; )
5755     {
5756       register dw_separate_line_info_ref line_info
5757         = &separate_line_info_table[lt_index];
5758
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
5766
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)
5773         {
5774           function = line_info->function;
5775
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);
5781
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);
5789         }
5790       else
5791         {
5792           /* ??? See the DW_LNS_advance_pc comment above.  */
5793           if (0)
5794             {
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);
5799
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);
5804             }
5805           else
5806             {
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);
5818             }
5819         }
5820       strcpy (prev_line_label, line_label);
5821
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)
5825         {
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);
5830
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]);
5835
5836           fputc ('\n', asm_out_file);
5837         }
5838
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)
5842         {
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))
5847             {
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);
5853
5854               fputc ('\n', asm_out_file);
5855             }
5856           else
5857             {
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);
5862
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);
5870             }
5871         }
5872       else
5873         {
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);
5879         }
5880
5881 #if 0
5882     cont:
5883 #endif
5884       ++lt_index;
5885
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)
5889         {
5890           current_file = 1;
5891           current_line = 1;
5892
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)
5896             {
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);
5901
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);
5906             }
5907           else
5908             {
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);
5920             }
5921
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);
5927
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);
5933         }
5934     }
5935
5936   /* Output the marker for the end of the line number info.  */
5937   ASM_OUTPUT_LABEL (asm_out_file, ".LTEND");
5938 }
5939 \f
5940 /* Given a pointer to a tree node for some base type, return a pointer to
5941    a DIE that describes the given type.
5942
5943    This routine must only be called for GCC type nodes that correspond to
5944    Dwarf base (fundamental) types.  */
5945
5946 static dw_die_ref
5947 base_type_die (type)
5948      register tree type;
5949 {
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);
5954
5955   if (TREE_CODE (type) == ERROR_MARK
5956       || TREE_CODE (type) == VOID_TYPE)
5957     return 0;
5958
5959   if (name)
5960     {
5961       if (TREE_CODE (name) == TYPE_DECL)
5962         name = DECL_NAME (name);
5963
5964       type_name = IDENTIFIER_POINTER (name);
5965     }
5966   else
5967     type_name = "__unknown__";
5968
5969   switch (TREE_CODE (type))
5970     {
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"))))
5980         {
5981           if (TREE_UNSIGNED (type))
5982             encoding = DW_ATE_unsigned;
5983           else
5984             encoding = DW_ATE_signed;
5985           break;
5986         }
5987       /* else fall through */
5988
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;
5996
5997     case REAL_TYPE:
5998       encoding = DW_ATE_float;
5999       break;
6000
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;
6009
6010     case BOOLEAN_TYPE:
6011       /* GNU FORTRAN/Ada/C++ BOOLEAN type.  */
6012       encoding = DW_ATE_boolean;
6013       break;
6014
6015     default:
6016       abort (); /* No other TREE_CODEs are Dwarf fundamental types.  */
6017     }
6018
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);
6022
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);
6027
6028   return base_type_result;
6029 }
6030
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.  */
6039
6040 static tree
6041 root_type (type)
6042      register tree type;
6043 {
6044   if (TREE_CODE (type) == ERROR_MARK)
6045     return error_mark_node;
6046
6047   switch (TREE_CODE (type))
6048     {
6049     case ERROR_MARK:
6050       return error_mark_node;
6051
6052     case POINTER_TYPE:
6053     case REFERENCE_TYPE:
6054       return type_main_variant (root_type (TREE_TYPE (type)));
6055
6056     default:
6057       return type_main_variant (type);
6058     }
6059 }
6060
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.  */
6063
6064 static inline int
6065 is_base_type (type)
6066      register tree type;
6067 {
6068   switch (TREE_CODE (type))
6069     {
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;
6078
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;
6093
6094     default:
6095       abort ();
6096     }
6097
6098   return 0;
6099 }
6100
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.  */
6103
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;
6110 {
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;
6115
6116   if (code != ERROR_MARK)
6117     {
6118       type = build_type_variant (type, is_const_type, is_volatile_type);
6119
6120       mod_type_die = lookup_type_die (type);
6121       if (mod_type_die)
6122         return mod_type_die;
6123
6124       /* Handle C typedef types. */
6125       if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
6126           && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
6127         {
6128           tree dtype = TREE_TYPE (TYPE_NAME (type));
6129           if (type == dtype)
6130             {
6131               /* For a named type, use the typedef.  */
6132               gen_type_die (type, context_die);
6133               mod_type_die = lookup_type_die (type);
6134             }
6135
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.  */
6145         }
6146
6147       if (mod_type_die)
6148         /* OK */;
6149       else if (is_const_type)
6150         {
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);
6153         }
6154       else if (is_volatile_type)
6155         {
6156           mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die);
6157           sub_die = modified_type_die (type, 0, 0, context_die);
6158         }
6159       else if (code == POINTER_TYPE)
6160         {
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);
6167         }
6168       else if (code == REFERENCE_TYPE)
6169         {
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);
6176         }
6177       else if (is_base_type (type))
6178         mod_type_die = base_type_die (type);
6179       else
6180         {
6181           gen_type_die (type, context_die);
6182
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 ();
6192         }
6193     }
6194
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);
6205
6206   if (sub_die != NULL)
6207     add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
6208
6209   return mod_type_die;
6210 }
6211
6212 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
6213    an enumerated type.   */
6214
6215 static inline int
6216 type_is_enum (type)
6217      register tree type;
6218 {
6219   return TREE_CODE (type) == ENUMERAL_TYPE;
6220 }
6221
6222 /* Return a location descriptor that designates a machine register.  */
6223
6224 static dw_loc_descr_ref
6225 reg_loc_descriptor (rtl)
6226      register rtx rtl;
6227 {
6228   register dw_loc_descr_ref loc_result = NULL;
6229   register unsigned reg = reg_number (rtl);
6230
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);
6235
6236   return loc_result;
6237 }
6238
6239 /* Return a location descriptor that designates a base+offset location.  */
6240
6241 static dw_loc_descr_ref
6242 based_loc_descr (reg, offset)
6243      unsigned reg;
6244      long int offset;
6245 {
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);
6253
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);
6260
6261   return loc_result;
6262 }
6263
6264 /* Return true if this RTL expression describes a base+offset calculation.  */
6265
6266 static inline int
6267 is_based_loc (rtl)
6268      register rtx rtl;
6269 {
6270     return (GET_CODE (rtl) == PLUS
6271             && ((GET_CODE (XEXP (rtl, 0)) == REG
6272                  && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
6273 }
6274
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.
6279
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.
6284
6285    MODE is the mode of the memory reference, needed to handle some
6286    autoincrement addressing modes.  */
6287
6288 static dw_loc_descr_ref
6289 mem_loc_descriptor (rtl, mode)
6290      register rtx rtl;
6291      enum machine_mode mode;
6292 {
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.  */
6298
6299 #ifdef ASM_SIMPLIFY_DWARF_ADDR
6300   rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
6301 #endif
6302
6303   switch (GET_CODE (rtl))
6304     {
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.  */
6309
6310       /* ... fall through ... */
6311
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);
6319
6320       /* ... fall through ... */
6321
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;
6338
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;
6343
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;
6354
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)));
6363                           
6364       /* ... fall through ... */
6365
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
6371         {
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));
6377         }
6378       break;
6379
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;
6387
6388     case CONST_INT:
6389       mem_loc_result = new_loc_descr (DW_OP_constu, INTVAL (rtl), 0);
6390       break;
6391
6392     default:
6393       abort ();
6394     }
6395
6396   return mem_loc_result;
6397 }
6398
6399 /* Return a descriptor that describes the concatenation of two locations.
6400    This is typically a complex variable.  */
6401
6402 static dw_loc_descr_ref
6403 concat_loc_descriptor (x0, x1)
6404      register rtx x0, x1;
6405 {
6406   dw_loc_descr_ref cc_loc_result = NULL;
6407
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));
6413
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));
6419
6420   return cc_loc_result;
6421 }
6422
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.  */
6428
6429 static dw_loc_descr_ref
6430 loc_descriptor (rtl)
6431      register rtx rtl;
6432 {
6433   dw_loc_descr_ref loc_result = NULL;
6434   switch (GET_CODE (rtl))
6435     {
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);
6443
6444       /* ... fall through ... */
6445
6446     case REG:
6447       loc_result = reg_loc_descriptor (rtl);
6448       break;
6449
6450     case MEM:
6451       loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
6452       break;
6453
6454     case CONCAT:
6455       loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
6456       break;
6457
6458     default:
6459       abort ();
6460     }
6461
6462   return loc_result;
6463 }
6464
6465 /* Given a value, round it up to the lowest multiple of `boundary'
6466    which is not less than the value itself.  */
6467
6468 static inline HOST_WIDE_INT
6469 ceiling (value, boundary)
6470      HOST_WIDE_INT value;
6471      unsigned int boundary;
6472 {
6473   return (((value + boundary - 1) / boundary) * boundary);
6474 }
6475
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.  */
6480
6481 static inline tree
6482 field_type (decl)
6483      register tree decl;
6484 {
6485   register tree type;
6486
6487   if (TREE_CODE (decl) == ERROR_MARK)
6488     return integer_type_node;
6489
6490   type = DECL_BIT_FIELD_TYPE (decl);
6491   if (type == NULL_TREE)
6492     type = TREE_TYPE (decl);
6493
6494   return type;
6495 }
6496
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.  */
6501
6502 static inline unsigned
6503 simple_type_align_in_bits (type)
6504      register tree type;
6505 {
6506   return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
6507 }
6508
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.  */
6514
6515 static inline unsigned HOST_WIDE_INT
6516 simple_type_size_in_bits (type)
6517      register tree type;
6518 {
6519   if (TREE_CODE (type) == ERROR_MARK)
6520     return BITS_PER_WORD;
6521   else
6522     {
6523       register tree type_size_tree = TYPE_SIZE (type);
6524
6525       if (! host_integerp (type_size_tree, 1))
6526         return TYPE_ALIGN (type);
6527
6528       return tree_low_cst (type_size_tree, 1);
6529     }
6530 }
6531
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).  */
6538
6539 static HOST_WIDE_INT
6540 field_byte_offset (decl)
6541      register tree decl;
6542 {
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;
6554
6555   if (TREE_CODE (decl) == ERROR_MARK)
6556     return 0;
6557
6558   if (TREE_CODE (decl) != FIELD_DECL)
6559     abort ();
6560
6561   type = field_type (decl);
6562   field_size_tree = DECL_SIZE (decl);
6563
6564   /* If there was an error, the size could be zero.  */
6565   if (! field_size_tree)
6566     {
6567       if (errorcount)
6568         return 0;
6569
6570       abort ();
6571     }
6572
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;
6578
6579   bitpos_int = int_bit_position (decl);
6580
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;
6586
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;
6590
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:
6600
6601          struct S { int field1; long long field2:31; };
6602
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).  */
6629
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;
6633
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;
6638
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;
6641
6642   /* Compute the offset of the containing object in bytes.  */
6643   object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes;
6644
6645   return object_offset_in_bytes;
6646 }
6647 \f
6648 /* The following routines define various Dwarf attributes and any data
6649    associated with them.  */
6650
6651 /* Add a location description attribute value to a DIE.
6652
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.  */
6656
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;
6662 {
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.  */
6671
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;
6686
6687   add_AT_loc (die, attr_kind, loc_descriptor (rtl));
6688 }
6689
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).  */
6708
6709 static void
6710 add_data_member_location_attribute (die, decl)
6711      register dw_die_ref die;
6712      register tree decl;
6713 {
6714   register unsigned long offset;
6715   register dw_loc_descr_ref loc_descr;
6716   register enum dwarf_location_atom op;
6717
6718   if (TREE_CODE (decl) == TREE_VEC)
6719     offset = tree_low_cst (BINFO_OFFSET (decl), 0);
6720   else
6721     offset = field_byte_offset (decl);
6722
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.  */
6726
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
6734
6735   loc_descr = new_loc_descr (op, offset, 0);
6736   add_AT_loc (die, DW_AT_data_member_location, loc_descr);
6737 }
6738
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".  */
6744
6745 static void
6746 add_const_value_attribute (die, rtl)
6747      register dw_die_ref die;
6748      register rtx rtl;
6749 {
6750   switch (GET_CODE (rtl))
6751     {
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;
6760
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.  */
6766       {
6767         register enum machine_mode mode = GET_MODE (rtl);
6768
6769         if (GET_MODE_CLASS (mode) == MODE_FLOAT)
6770           {
6771             register unsigned length = GET_MODE_SIZE (mode) / sizeof (long);
6772             long array[4];
6773             REAL_VALUE_TYPE rv;
6774
6775             REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
6776             switch (mode)
6777               {
6778               case SFmode:
6779                 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]);
6780                 break;
6781
6782               case DFmode:
6783                 REAL_VALUE_TO_TARGET_DOUBLE (rv, array);
6784                 break;
6785
6786               case XFmode:
6787               case TFmode:
6788                 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array);
6789                 break;
6790
6791               default:
6792                 abort ();
6793               }
6794
6795             add_AT_float (die, DW_AT_const_value, length, array);
6796           }
6797         else
6798           add_AT_long_long (die, DW_AT_const_value,
6799                             CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
6800       }
6801       break;
6802
6803     case CONST_STRING:
6804       add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
6805       break;
6806
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;
6812
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;
6826
6827     default:
6828       /* No other kinds of rtx should be possible here.  */
6829       abort ();
6830     }
6831
6832 }
6833
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.  */
6844
6845 static void
6846 add_location_or_const_value_attribute (die, decl)
6847      register dw_die_ref die;
6848      register tree decl;
6849 {
6850   register rtx rtl;
6851   register tree declared_type;
6852   register tree passed_type;
6853
6854   if (TREE_CODE (decl) == ERROR_MARK)
6855     return;
6856
6857   if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
6858     abort ();
6859
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.
6863
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.
6871
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.
6876
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.
6883
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.
6893
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.
6907
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.
6917
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).  */
6934
6935   /* Use DECL_RTL as the "location" unless we find something better.  */
6936   rtl = DECL_RTL (decl);
6937
6938   if (TREE_CODE (decl) == PARM_DECL)
6939     {
6940       if (rtl == NULL_RTX || is_pseudo_reg (rtl))
6941         {
6942           declared_type = type_main_variant (TREE_TYPE (decl));
6943           passed_type = type_main_variant (DECL_ARG_TYPE (decl));
6944
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);
6955         }
6956
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
6976                      )
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))
6982         {
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));
6987         }
6988     }
6989
6990   if (rtl == NULL_RTX)
6991     return;
6992
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
6998
6999   switch (GET_CODE (rtl))
7000     {
7001     case ADDRESSOF:
7002       /* The address of a variable that was optimized away; don't emit
7003          anything.  */
7004       break;
7005
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;
7016
7017     case MEM:
7018     case REG:
7019     case SUBREG:
7020     case CONCAT:
7021       add_AT_location_description (die, DW_AT_location, rtl);
7022       break;
7023
7024     default:
7025       abort ();
7026     }
7027 }
7028
7029 /* Generate an DW_AT_name attribute given some string value to be included as
7030    the value of the attribute.  */
7031
7032 static inline void
7033 add_name_attribute (die, name_string)
7034      register dw_die_ref die;
7035      register const char *name_string;
7036 {
7037   if (name_string != NULL && *name_string != 0)
7038     {
7039       if (demangle_name_func)
7040         name_string = (*demangle_name_func) (name_string);
7041
7042       add_AT_string (die, DW_AT_name, name_string);
7043     }
7044 }
7045
7046 /* Given a tree node describing an array bound (either lower or upper) output
7047    a representation for that bound.  */
7048
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;
7054 {
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;
7060
7061   switch (TREE_CODE (bound))
7062     {
7063     case ERROR_MARK:
7064       return;
7065
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 */
7073         ;
7074       else
7075         add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
7076       break;
7077
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;
7083       
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.
7103
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)
7108         {
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);
7112
7113           /* If the RTL for the SAVE_EXPR is memory, handle the case where
7114              it references an outer function's frame.  */
7115
7116           if (GET_CODE (loc) == MEM)
7117             {
7118               rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound);
7119
7120               if (XEXP (loc, 0) != new_addr)
7121                 loc = gen_rtx_MEM (GET_MODE (loc), new_addr);
7122             }
7123
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);
7128         }
7129
7130       /* Else leave out the attribute.  */
7131       break;
7132
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;
7139
7140     default:
7141       abort ();
7142     }
7143 }
7144
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.  */
7147
7148 static void
7149 add_subscript_info (type_die, type)
7150      register dw_die_ref type_die;
7151      register tree type;
7152 {
7153 #ifndef MIPS_DEBUGGING_INFO
7154   register unsigned dimension_number;
7155 #endif
7156   register tree lower, upper;
7157   register dw_die_ref subrange_die;
7158
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.  */
7167
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++)
7176     {
7177 #endif
7178       register tree domain = TYPE_DOMAIN (type);
7179
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)
7185         {
7186           /* We have an array type with specified bounds.  */
7187           lower = TYPE_MIN_VALUE (domain);
7188           upper = TYPE_MAX_VALUE (domain);
7189
7190           /* define the index type.  */
7191           if (TREE_TYPE (domain))
7192             {
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)
7200                 ;       
7201               else
7202                 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
7203                                     type_die);
7204             }
7205
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.  */
7212
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);
7216         }
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.  */
7221         {;}
7222       
7223
7224 #ifndef MIPS_DEBUGGING_INFO
7225     }
7226 #endif
7227 }
7228
7229 static void
7230 add_byte_size_attribute (die, tree_node)
7231      dw_die_ref die;
7232      register tree tree_node;
7233 {
7234   register unsigned size;
7235
7236   switch (TREE_CODE (tree_node))
7237     {
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 ();
7256     }
7257
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.  */
7262
7263   add_AT_unsigned (die, DW_AT_byte_size, size);
7264 }
7265
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.
7270
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).
7278
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).  */
7282
7283 static inline void
7284 add_bit_offset_attribute (die, decl)
7285      register dw_die_ref die;
7286      register tree decl;
7287 {
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;
7294
7295   /* Must be a field and a bit field.  */
7296   if (!type
7297       || TREE_CODE (decl) != FIELD_DECL)
7298     abort ();
7299
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;
7306
7307   bitpos_int = int_bit_position (decl);
7308
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;
7316
7317   if (! BYTES_BIG_ENDIAN)
7318     {
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);
7321     }
7322
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);
7327
7328   add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
7329 }
7330
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.  */
7333
7334 static inline void
7335 add_bit_size_attribute (die, decl)
7336      register dw_die_ref die;
7337      register tree decl;
7338 {
7339   /* Must be a field and a bit field.  */
7340   if (TREE_CODE (decl) != FIELD_DECL
7341       || ! DECL_BIT_FIELD_TYPE (decl))
7342     abort ();
7343
7344   if (host_integerp (DECL_SIZE (decl), 1))
7345     add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
7346 }
7347
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.  */
7350
7351 static inline void
7352 add_prototyped_attribute (die, func_type)
7353      register dw_die_ref die;
7354      register tree func_type;
7355 {
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);
7359 }
7360
7361
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.  */
7365
7366 static inline void
7367 add_abstract_origin_attribute (die, origin)
7368      register dw_die_ref die;
7369      register tree origin;
7370 {
7371   dw_die_ref origin_die = NULL;
7372
7373   if (TREE_CODE (origin) != FUNCTION_DECL)
7374     {
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.
7378
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);
7387     }
7388
7389   if (TREE_CODE_CLASS (TREE_CODE (origin)) == 'd')
7390     origin_die = lookup_decl_die (origin);
7391   else if (TREE_CODE_CLASS (TREE_CODE (origin)) == 't')
7392     origin_die = lookup_type_die (origin);
7393
7394   if (origin_die == NULL)
7395     abort ();
7396   
7397   add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
7398 }
7399
7400 /* We do not currently support the pure_virtual attribute.  */
7401
7402 static inline void
7403 add_pure_or_virtual_attribute (die, func_decl)
7404      register dw_die_ref die;
7405      register tree func_decl;
7406 {
7407   if (DECL_VINDEX (func_decl))
7408     {
7409       add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
7410
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));
7416
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)));
7421     }
7422 }
7423 \f
7424 /* Add source coordinate attributes for the given decl.  */
7425
7426 static void
7427 add_src_coords_attributes (die, decl)
7428      register dw_die_ref die;
7429      register tree decl;
7430 {
7431   register unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
7432
7433   add_AT_unsigned (die, DW_AT_decl_file, file_index);
7434   add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
7435 }
7436
7437 /* Add an DW_AT_name attribute and source coordinate attribute for the
7438    given decl, but only if it actually has a name.  */
7439
7440 static void
7441 add_name_and_src_coords_attributes (die, decl)
7442      register dw_die_ref die;
7443      register tree decl;
7444 {
7445   register tree decl_name;
7446
7447   decl_name = DECL_NAME (decl); 
7448   if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
7449     {
7450       add_name_attribute (die, dwarf2_name (decl, 0));
7451       if (! DECL_ARTIFICIAL (decl))
7452         add_src_coords_attributes (die, decl);
7453
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)));
7459     }
7460 }
7461
7462 /* Push a new declaration scope. */
7463
7464 static void
7465 push_decl_scope (scope)
7466      tree scope;
7467 {
7468   /* Make room in the decl_scope_table, if necessary.  */
7469   if (decl_scope_table_allocated == decl_scope_depth)
7470     {
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));
7475     }
7476
7477   decl_scope_table[decl_scope_depth] = scope;
7478   decl_scope_depth++;
7479 }
7480
7481 /* Pop a declaration scope.  */
7482 static inline void
7483 pop_decl_scope ()
7484 {
7485   if (decl_scope_depth <= 0)
7486     abort ();
7487   --decl_scope_depth;
7488 }
7489
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.  */
7495
7496 static dw_die_ref
7497 scope_die_for (t, context_die)
7498     register tree t; 
7499     register dw_die_ref context_die;
7500 {
7501   register dw_die_ref scope_die = NULL;
7502   register tree containing_scope;
7503   register int i;
7504
7505   /* Non-types always go in the current scope.  */
7506   if (! TYPE_P (t))
7507     abort ();
7508
7509   containing_scope = TYPE_CONTEXT (t);
7510
7511   /* Ignore namespaces for the moment.  */
7512   if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
7513     containing_scope = NULL_TREE;
7514
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;
7520
7521   if (containing_scope == NULL_TREE)
7522     scope_die = comp_unit_die;
7523   else if (TYPE_P (containing_scope))
7524     {
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.  */
7528
7529       for (i = decl_scope_depth - 1; i >= 0; --i)
7530         if (decl_scope_table[i] == containing_scope)
7531           break;
7532
7533       if (i < 0)
7534         {
7535           if (debug_info_level > DINFO_LEVEL_TERSE
7536               && !TREE_ASM_WRITTEN (containing_scope))
7537             abort ();
7538
7539           /* If none of the current dies are suitable, we get file scope.  */
7540           scope_die = comp_unit_die;
7541         }
7542       else
7543         scope_die = lookup_type_die (containing_scope);
7544     }
7545   else
7546     scope_die = context_die;
7547
7548   return scope_die;
7549 }
7550
7551 /* Returns nonzero iff CONTEXT_DIE is internal to a function.  */
7552
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;
7557 {
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;
7563 }
7564
7565 /* Returns nonzero iff CONTEXT_DIE is a class.  */
7566
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;
7571 {
7572   return (context_die
7573           && (context_die->die_tag == DW_TAG_structure_type
7574               || context_die->die_tag == DW_TAG_union_type));
7575 }
7576
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.  */
7580
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;
7588 {
7589   register enum tree_code code  = TREE_CODE (type);
7590   register dw_die_ref type_die  = NULL;
7591
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);
7599
7600   if (code == ERROR_MARK)
7601     return;
7602
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;
7608
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);
7615 }
7616
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.  */
7620
7621 static char *
7622 type_tag (type)
7623      register tree type;
7624 {
7625   register char *name = 0;
7626
7627   if (TYPE_NAME (type) != 0)
7628     {
7629       register tree t = 0;
7630
7631       /* Find the IDENTIFIER_NODE for the type name.  */
7632       if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
7633         t = TYPE_NAME (type);
7634
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));
7641
7642       /* Now get the name as a string, or invent one.  */
7643       if (t != 0)
7644         name = IDENTIFIER_POINTER (t);
7645     }
7646
7647   return (name == 0 || *name == '\0') ? 0 : name;
7648 }
7649
7650 /* Return the type associated with a data member, make a special check
7651    for bit field types.  */
7652
7653 static inline tree
7654 member_declared_type (member)
7655      register tree member;
7656 {
7657   return (DECL_BIT_FIELD_TYPE (member)
7658           ? DECL_BIT_FIELD_TYPE (member)
7659           : TREE_TYPE (member));
7660 }
7661
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.  */
7664
7665 #if 0
7666 static char *
7667 decl_start_label (decl)
7668      register tree decl;
7669 {
7670   rtx x;
7671   char *fnname;
7672   x = DECL_RTL (decl);
7673   if (GET_CODE (x) != MEM)
7674     abort ();
7675
7676   x = XEXP (x, 0);
7677   if (GET_CODE (x) != SYMBOL_REF)
7678     abort ();
7679
7680   fnname = XSTR (x, 0);
7681   return fnname;
7682 }
7683 #endif
7684 \f
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().  */
7688
7689 static void
7690 gen_array_type_die (type, context_die)
7691      register tree type;
7692      register dw_die_ref context_die;
7693 {
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;
7697
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
7704
7705   array_die = new_die (DW_TAG_array_type, scope_die);
7706
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
7717
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);
7726
7727   add_name_attribute (array_die, type_tag (type));
7728   equate_type_number_to_die (type, array_die);
7729
7730   /* Add representation of the type of the elements of this array type.  */
7731   element_type = TREE_TYPE (type);
7732
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);
7740
7741   gen_type_die (element_type, context_die);
7742 #endif
7743
7744   add_type_attribute (array_die, element_type, 0, 0, context_die);
7745 }
7746
7747 static void
7748 gen_set_type_die (type, context_die)
7749      register tree type;
7750      register dw_die_ref context_die;
7751 {
7752   register dw_die_ref type_die
7753     = new_die (DW_TAG_set_type, scope_die_for (type, context_die));
7754
7755   equate_type_number_to_die (type, type_die);
7756   add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
7757 }
7758
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;
7764 {
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
7770     {
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);
7774     }
7775
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));
7780 }
7781 #endif
7782
7783 /* Remember a type in the incomplete_types_list.  */
7784
7785 static void
7786 add_incomplete_type (type)
7787      tree type;
7788 {
7789   if (incomplete_types == incomplete_types_allocated)
7790     {
7791       incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT;
7792       incomplete_types_list
7793         = (tree *) xrealloc (incomplete_types_list,
7794                              sizeof (tree) * incomplete_types_allocated);
7795     }
7796
7797   incomplete_types_list[incomplete_types++] = type;
7798 }
7799
7800 /* Walk through the list of incomplete types again, trying once more to
7801    emit full debugging info for them.  */
7802
7803 static void
7804 retry_incomplete_types ()
7805 {
7806   register tree type;
7807
7808   while (incomplete_types)
7809     {
7810       --incomplete_types;
7811       type = incomplete_types_list[incomplete_types];
7812       gen_type_die (type, comp_unit_die);
7813     }
7814 }
7815
7816 /* Generate a DIE to represent an inlined instance of an enumeration type.  */
7817
7818 static void
7819 gen_inlined_enumeration_type_die (type, context_die)
7820      register tree type;
7821      register dw_die_ref context_die;
7822 {
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);
7828 }
7829
7830 /* Generate a DIE to represent an inlined instance of a structure type.  */
7831
7832 static void
7833 gen_inlined_structure_type_die (type, context_die)
7834      register tree type;
7835      register dw_die_ref context_die;
7836 {
7837   register dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die);
7838
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);
7842 }
7843
7844 /* Generate a DIE to represent an inlined instance of a union type.  */
7845
7846 static void
7847 gen_inlined_union_type_die (type, context_die)
7848      register tree type;
7849      register dw_die_ref context_die;
7850 {
7851   register dw_die_ref type_die = new_die (DW_TAG_union_type, context_die);
7852
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);
7856 }
7857
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.  */
7862
7863 static void
7864 gen_enumeration_type_die (type, context_die)
7865      register tree type;
7866      register dw_die_ref context_die;
7867 {
7868   register dw_die_ref type_die = lookup_type_die (type);
7869
7870   if (type_die == NULL)
7871     {
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));
7876     }
7877   else if (! TYPE_SIZE (type))
7878     return;
7879   else
7880     remove_AT (type_die, DW_AT_declaration);
7881
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))
7886     {
7887       register tree link;
7888
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));
7893
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);
7898
7899       for (link = TYPE_FIELDS (type);
7900            link != NULL; link = TREE_CHAIN (link))
7901         {
7902           register dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die);
7903
7904           add_name_attribute (enum_die,
7905                               IDENTIFIER_POINTER (TREE_PURPOSE (link)));
7906
7907           if (host_integerp (TREE_VALUE (link), 0))
7908             add_AT_unsigned (enum_die, DW_AT_const_value,
7909                              tree_low_cst (TREE_VALUE (link), 0));
7910         }
7911     }
7912   else
7913     add_AT_flag (type_die, DW_AT_declaration, 1);
7914 }
7915
7916
7917 /* Generate a DIE to represent either a real live formal parameter decl or to
7918    represent just the type of some formal parameter position in some function
7919    type.
7920
7921    Note that this routine is a bit unusual because its argument may be a
7922    ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
7923    represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
7924    node.  If it's the former then this function is being called to output a
7925    DIE to represent a formal parameter object (or some inlining thereof).  If
7926    it's the latter, then this function is only being called to output a
7927    DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
7928    argument type of some subprogram type.  */
7929
7930 static dw_die_ref
7931 gen_formal_parameter_die (node, context_die)
7932      register tree node;
7933      register dw_die_ref context_die;
7934 {
7935   register dw_die_ref parm_die
7936     = new_die (DW_TAG_formal_parameter, context_die);
7937   register tree origin;
7938
7939   switch (TREE_CODE_CLASS (TREE_CODE (node)))
7940     {
7941     case 'd':
7942       origin = decl_ultimate_origin (node);
7943       if (origin != NULL)
7944         add_abstract_origin_attribute (parm_die, origin);
7945       else
7946         {
7947           add_name_and_src_coords_attributes (parm_die, node);
7948           add_type_attribute (parm_die, TREE_TYPE (node),
7949                               TREE_READONLY (node),
7950                               TREE_THIS_VOLATILE (node),
7951                               context_die);
7952           if (DECL_ARTIFICIAL (node))
7953             add_AT_flag (parm_die, DW_AT_artificial, 1);
7954         }
7955
7956       equate_decl_number_to_die (node, parm_die);
7957       if (! DECL_ABSTRACT (node))
7958         add_location_or_const_value_attribute (parm_die, node);
7959
7960       break;
7961
7962     case 't':
7963       /* We were called with some kind of a ..._TYPE node.  */
7964       add_type_attribute (parm_die, node, 0, 0, context_die);
7965       break;
7966
7967     default:
7968       abort ();
7969     }
7970
7971   return parm_die;
7972 }
7973
7974 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
7975    at the end of an (ANSI prototyped) formal parameters list.  */
7976
7977 static void
7978 gen_unspecified_parameters_die (decl_or_type, context_die)
7979      register tree decl_or_type ATTRIBUTE_UNUSED;
7980      register dw_die_ref context_die;
7981 {
7982   new_die (DW_TAG_unspecified_parameters, context_die);
7983 }
7984
7985 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
7986    DW_TAG_unspecified_parameters DIE) to represent the types of the formal
7987    parameters as specified in some function type specification (except for
7988    those which appear as part of a function *definition*).
7989
7990    Note we must be careful here to output all of the parameter DIEs before*
7991    we output any DIEs needed to represent the types of the formal parameters.
7992    This keeps svr4 SDB happy because it (incorrectly) thinks that the first
7993    non-parameter DIE it sees ends the formal parameter list.  */
7994
7995 static void
7996 gen_formal_types_die (function_or_method_type, context_die)
7997      register tree function_or_method_type;
7998      register dw_die_ref context_die;
7999 {
8000   register tree link;
8001   register tree formal_type = NULL;
8002   register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
8003
8004 #if 0
8005   /* In the case where we are generating a formal types list for a C++
8006      non-static member function type, skip over the first thing on the
8007      TYPE_ARG_TYPES list because it only represents the type of the hidden
8008      `this pointer'.  The debugger should be able to figure out (without
8009      being explicitly told) that this non-static member function type takes a 
8010      `this pointer' and should be able to figure what the type of that hidden 
8011      parameter is from the DW_AT_member attribute of the parent
8012      DW_TAG_subroutine_type DIE.  */
8013   if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
8014     first_parm_type = TREE_CHAIN (first_parm_type);
8015 #endif
8016
8017   /* Make our first pass over the list of formal parameter types and output a 
8018      DW_TAG_formal_parameter DIE for each one.  */
8019   for (link = first_parm_type; link; link = TREE_CHAIN (link))
8020     {
8021       register dw_die_ref parm_die;
8022       
8023       formal_type = TREE_VALUE (link);
8024       if (formal_type == void_type_node)
8025         break;
8026
8027       /* Output a (nameless) DIE to represent the formal parameter itself.  */
8028       parm_die = gen_formal_parameter_die (formal_type, context_die);
8029       if (TREE_CODE (function_or_method_type) == METHOD_TYPE
8030           && link == first_parm_type)
8031         add_AT_flag (parm_die, DW_AT_artificial, 1);
8032     }
8033
8034   /* If this function type has an ellipsis, add a
8035      DW_TAG_unspecified_parameters DIE to the end of the parameter list.  */
8036   if (formal_type != void_type_node)
8037     gen_unspecified_parameters_die (function_or_method_type, context_die);
8038
8039   /* Make our second (and final) pass over the list of formal parameter types 
8040      and output DIEs to represent those types (as necessary).  */
8041   for (link = TYPE_ARG_TYPES (function_or_method_type);
8042        link;
8043        link = TREE_CHAIN (link))
8044     {
8045       formal_type = TREE_VALUE (link);
8046       if (formal_type == void_type_node)
8047         break;
8048
8049       gen_type_die (formal_type, context_die);
8050     }
8051 }
8052
8053 /* We want to generate the DIE for TYPE so that we can generate the
8054    die for MEMBER, which has been defined; we will need to refer back
8055    to the member declaration nested within TYPE.  If we're trying to
8056    generate minimal debug info for TYPE, processing TYPE won't do the
8057    trick; we need to attach the member declaration by hand.  */
8058
8059 static void
8060 gen_type_die_for_member (type, member, context_die)
8061      tree type, member;
8062      dw_die_ref context_die;
8063 {
8064   gen_type_die (type, context_die);
8065
8066   /* If we're trying to avoid duplicate debug info, we may not have
8067      emitted the member decl for this function.  Emit it now.  */
8068   if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
8069       && ! lookup_decl_die (member))
8070     {
8071       if (decl_ultimate_origin (member))
8072         abort ();
8073
8074       push_decl_scope (type);
8075       if (TREE_CODE (member) == FUNCTION_DECL)
8076         gen_subprogram_die (member, lookup_type_die (type));
8077       else
8078         gen_variable_die (member, lookup_type_die (type));
8079       pop_decl_scope ();
8080     }
8081 }
8082
8083 /* Generate the DWARF2 info for the "abstract" instance
8084    of a function which we may later generate inlined and/or
8085    out-of-line instances of.  */
8086
8087 static void
8088 gen_abstract_function (decl)
8089      tree decl;
8090 {
8091   register dw_die_ref old_die = lookup_decl_die (decl);
8092   tree save_fn;
8093
8094   if (old_die && get_AT_unsigned (old_die, DW_AT_inline))
8095     /* We've already generated the abstract instance.  */
8096     return;
8097
8098   save_fn = current_function_decl;
8099   current_function_decl = decl;
8100
8101   set_decl_abstract_flags (decl, 1);
8102   dwarf2out_decl (decl);
8103   set_decl_abstract_flags (decl, 0);
8104
8105   current_function_decl = save_fn;
8106 }
8107
8108 /* Generate a DIE to represent a declared function (either file-scope or
8109    block-local).  */
8110
8111 static void
8112 gen_subprogram_die (decl, context_die)
8113      register tree decl;
8114      register dw_die_ref context_die;
8115 {
8116   char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
8117   register tree origin = decl_ultimate_origin (decl);
8118   register dw_die_ref subr_die;
8119   register rtx fp_reg;
8120   register tree fn_arg_types;
8121   register tree outer_scope;
8122   register dw_die_ref old_die = lookup_decl_die (decl);
8123   register int declaration = (current_function_decl != decl
8124                               || class_scope_p (context_die));
8125
8126   /* Note that it is possible to have both DECL_ABSTRACT and `declaration'
8127      be true, if we started to generate the abstract instance of an inline,
8128      decided to output its containing class, and proceeded to emit the
8129      declaration of the inline from the member list for the class.  In that
8130      case, `declaration' takes priority; we'll get back to the abstract
8131      instance when we're done with the class.  */
8132
8133   if (origin != NULL)
8134     {
8135       if (declaration && ! local_scope_p (context_die))
8136         abort ();
8137
8138       subr_die = new_die (DW_TAG_subprogram, context_die);
8139       add_abstract_origin_attribute (subr_die, origin);
8140     }
8141   else if (old_die && DECL_ABSTRACT (decl)
8142            && get_AT_unsigned (old_die, DW_AT_inline))
8143     {
8144       /* This must be a redefinition of an extern inline function.
8145          We can just reuse the old die here.  */
8146       subr_die = old_die;
8147
8148       /* Clear out the inlined attribute and parm types.  */
8149       remove_AT (subr_die, DW_AT_inline);
8150       remove_children (subr_die);
8151     }
8152   else if (old_die)
8153     {
8154       register unsigned file_index
8155         = lookup_filename (DECL_SOURCE_FILE (decl));
8156
8157       if (get_AT_flag (old_die, DW_AT_declaration) != 1)
8158         {
8159           /* ??? This can happen if there is a bug in the program, for
8160              instance, if it has duplicate function definitions.  Ideally,
8161              we should detect this case and ignore it.  For now, if we have
8162              already reported an error, any error at all, then assume that
8163              we got here because of a input error, not a dwarf2 bug.  */
8164           if (errorcount)
8165             return;
8166           abort ();
8167         }
8168
8169       /* If the definition comes from the same place as the declaration,
8170          maybe use the old DIE.  We always want the DIE for this function
8171          that has the *_pc attributes to be under comp_unit_die so the
8172          debugger can find it.  For inlines, that is the concrete instance,
8173          so we can use the old DIE here.  For non-inline methods, we want a
8174          specification DIE at toplevel, so we need a new DIE.  For local
8175          class methods, this doesn't apply; we just use the old DIE.  */
8176       if ((DECL_ABSTRACT (decl) || old_die->die_parent == comp_unit_die
8177            || context_die == NULL)
8178           && (DECL_ARTIFICIAL (decl)
8179               || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
8180                   && (get_AT_unsigned (old_die, DW_AT_decl_line)
8181                       == (unsigned)DECL_SOURCE_LINE (decl)))))
8182         {
8183           subr_die = old_die;
8184
8185           /* Clear out the declaration attribute and the parm types.  */
8186           remove_AT (subr_die, DW_AT_declaration);
8187           remove_children (subr_die);
8188         }
8189       else
8190         {
8191           subr_die = new_die (DW_TAG_subprogram, context_die);
8192           add_AT_die_ref (subr_die, DW_AT_specification, old_die);
8193           if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
8194             add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
8195           if (get_AT_unsigned (old_die, DW_AT_decl_line)
8196               != (unsigned)DECL_SOURCE_LINE (decl))
8197             add_AT_unsigned
8198               (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
8199         }
8200     }
8201   else
8202     {
8203       subr_die = new_die (DW_TAG_subprogram, context_die);
8204                          
8205       if (TREE_PUBLIC (decl))
8206         add_AT_flag (subr_die, DW_AT_external, 1);
8207
8208       add_name_and_src_coords_attributes (subr_die, decl);
8209       if (debug_info_level > DINFO_LEVEL_TERSE)
8210         {
8211           register tree type = TREE_TYPE (decl);
8212
8213           add_prototyped_attribute (subr_die, type);
8214           add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die);
8215         }
8216
8217       add_pure_or_virtual_attribute (subr_die, decl);
8218       if (DECL_ARTIFICIAL (decl))
8219         add_AT_flag (subr_die, DW_AT_artificial, 1);
8220       if (TREE_PROTECTED (decl))
8221         add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
8222       else if (TREE_PRIVATE (decl))
8223         add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
8224     }
8225
8226   if (declaration)
8227     {
8228       if (! origin)
8229         add_AT_flag (subr_die, DW_AT_declaration, 1);
8230
8231       /* The first time we see a member function, it is in the context of
8232          the class to which it belongs.  We make sure of this by emitting
8233          the class first.  The next time is the definition, which is
8234          handled above.  The two may come from the same source text.  */
8235       if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl))
8236         equate_decl_number_to_die (decl, subr_die);
8237     }
8238   else if (DECL_ABSTRACT (decl))
8239     {
8240       if (DECL_INLINE (decl) && !flag_no_inline)
8241         {
8242           /* ??? Checking DECL_DEFER_OUTPUT is correct for static
8243              inline functions, but not for extern inline functions.
8244              We can't get this completely correct because information
8245              about whether the function was declared inline is not
8246              saved anywhere.  */
8247           if (DECL_DEFER_OUTPUT (decl))
8248             add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
8249           else
8250             add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
8251         }
8252       else
8253         add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
8254
8255       equate_decl_number_to_die (decl, subr_die);
8256     }
8257   else if (!DECL_EXTERNAL (decl))
8258     {
8259       if (origin == NULL_TREE)
8260         equate_decl_number_to_die (decl, subr_die);
8261
8262       ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
8263                                    current_funcdef_number);
8264       add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
8265       ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
8266                                    current_funcdef_number);
8267       add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
8268
8269       add_pubname (decl, subr_die);
8270       add_arange (decl, subr_die);
8271
8272 #ifdef MIPS_DEBUGGING_INFO
8273       /* Add a reference to the FDE for this routine.  */
8274       add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
8275 #endif
8276
8277       /* Define the "frame base" location for this routine.  We use the
8278          frame pointer or stack pointer registers, since the RTL for local
8279          variables is relative to one of them.  */
8280       fp_reg
8281         = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
8282       add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
8283
8284 #if 0
8285       /* ??? This fails for nested inline functions, because context_display
8286          is not part of the state saved/restored for inline functions.  */
8287       if (current_function_needs_context)
8288         add_AT_location_description (subr_die, DW_AT_static_link,
8289                                      lookup_static_chain (decl));
8290 #endif
8291     }
8292
8293   /* Now output descriptions of the arguments for this function. This gets
8294      (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list 
8295      for a FUNCTION_DECL doesn't indicate cases where there was a trailing
8296      `...' at the end of the formal parameter list.  In order to find out if
8297      there was a trailing ellipsis or not, we must instead look at the type
8298      associated with the FUNCTION_DECL.  This will be a node of type
8299      FUNCTION_TYPE. If the chain of type nodes hanging off of this
8300      FUNCTION_TYPE node ends with a void_type_node then there should *not* be 
8301      an ellipsis at the end.  */
8302
8303   /* In the case where we are describing a mere function declaration, all we
8304      need to do here (and all we *can* do here) is to describe the *types* of 
8305      its formal parameters.  */
8306   if (debug_info_level <= DINFO_LEVEL_TERSE)
8307     ;
8308   else if (declaration)
8309     gen_formal_types_die (TREE_TYPE (decl), subr_die);
8310   else
8311     {
8312       /* Generate DIEs to represent all known formal parameters */
8313       register tree arg_decls = DECL_ARGUMENTS (decl);
8314       register tree parm;
8315
8316       /* When generating DIEs, generate the unspecified_parameters DIE
8317          instead if we come across the arg "__builtin_va_alist" */
8318       for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
8319         if (TREE_CODE (parm) == PARM_DECL)
8320           {
8321             if (DECL_NAME (parm)
8322                 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
8323                             "__builtin_va_alist"))
8324               gen_unspecified_parameters_die (parm, subr_die);
8325             else
8326               gen_decl_die (parm, subr_die);
8327           }
8328
8329       /* Decide whether we need a unspecified_parameters DIE at the end.
8330          There are 2 more cases to do this for: 1) the ansi ... declaration - 
8331          this is detectable when the end of the arg list is not a
8332          void_type_node 2) an unprototyped function declaration (not a
8333          definition).  This just means that we have no info about the
8334          parameters at all.  */
8335       fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
8336       if (fn_arg_types != NULL)
8337         {
8338           /* this is the prototyped case, check for ...  */
8339           if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
8340             gen_unspecified_parameters_die (decl, subr_die);
8341         }
8342       else if (DECL_INITIAL (decl) == NULL_TREE)
8343         gen_unspecified_parameters_die (decl, subr_die);
8344     }
8345
8346   /* Output Dwarf info for all of the stuff within the body of the function
8347      (if it has one - it may be just a declaration).  */
8348   outer_scope = DECL_INITIAL (decl);
8349
8350   /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
8351      node created to represent a function. This outermost BLOCK actually
8352      represents the outermost binding contour for the function, i.e. the
8353      contour in which the function's formal parameters and labels get
8354      declared. Curiously, it appears that the front end doesn't actually
8355      put the PARM_DECL nodes for the current function onto the BLOCK_VARS
8356      list for this outer scope.  (They are strung off of the DECL_ARGUMENTS
8357      list for the function instead.) The BLOCK_VARS list for the
8358      `outer_scope' does provide us with a list of the LABEL_DECL nodes for
8359      the function however, and we output DWARF info for those in
8360      decls_for_scope.  Just within the `outer_scope' there will be a BLOCK
8361      node representing the function's outermost pair of curly braces, and
8362      any blocks used for the base and member initializers of a C++
8363      constructor function.  */
8364   if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
8365     {
8366       current_function_has_inlines = 0;
8367       decls_for_scope (outer_scope, subr_die, 0);
8368
8369 #if 0 && defined (MIPS_DEBUGGING_INFO)
8370       if (current_function_has_inlines)
8371         {
8372           add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
8373           if (! comp_unit_has_inlines)
8374             {
8375               add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
8376               comp_unit_has_inlines = 1;
8377             }
8378         }
8379 #endif
8380     }
8381 }
8382
8383 /* Generate a DIE to represent a declared data object.  */
8384
8385 static void
8386 gen_variable_die (decl, context_die)
8387      register tree decl;
8388      register dw_die_ref context_die;
8389 {
8390   register tree origin = decl_ultimate_origin (decl);
8391   register dw_die_ref var_die = new_die (DW_TAG_variable, context_die);
8392
8393   dw_die_ref old_die = lookup_decl_die (decl);
8394   int declaration = (DECL_EXTERNAL (decl)
8395                      || class_scope_p (context_die));
8396
8397   if (origin != NULL)
8398     add_abstract_origin_attribute (var_die, origin);
8399   /* Loop unrolling can create multiple blocks that refer to the same
8400      static variable, so we must test for the DW_AT_declaration flag.  */
8401   /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
8402      copy decls and set the DECL_ABSTRACT flag on them instead of
8403      sharing them.  */
8404   else if (old_die && TREE_STATIC (decl)
8405            && get_AT_flag (old_die, DW_AT_declaration) == 1)
8406     {
8407       /* This is a definition of a C++ class level static.  */
8408       add_AT_die_ref (var_die, DW_AT_specification, old_die);
8409       if (DECL_NAME (decl))
8410         {
8411           register unsigned file_index
8412             = lookup_filename (DECL_SOURCE_FILE (decl));
8413
8414           if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
8415             add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
8416
8417           if (get_AT_unsigned (old_die, DW_AT_decl_line)
8418               != (unsigned)DECL_SOURCE_LINE (decl))
8419
8420             add_AT_unsigned (var_die, DW_AT_decl_line,
8421                              DECL_SOURCE_LINE (decl));
8422         }
8423     }
8424   else
8425     {
8426       add_name_and_src_coords_attributes (var_die, decl);
8427       add_type_attribute (var_die, TREE_TYPE (decl),
8428                           TREE_READONLY (decl),
8429                           TREE_THIS_VOLATILE (decl), context_die);
8430
8431       if (TREE_PUBLIC (decl))
8432         add_AT_flag (var_die, DW_AT_external, 1);
8433
8434       if (DECL_ARTIFICIAL (decl))
8435         add_AT_flag (var_die, DW_AT_artificial, 1);
8436
8437       if (TREE_PROTECTED (decl))
8438         add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
8439
8440       else if (TREE_PRIVATE (decl))
8441         add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
8442     }
8443
8444   if (declaration)
8445     add_AT_flag (var_die, DW_AT_declaration, 1);
8446   
8447   if (class_scope_p (context_die) || DECL_ABSTRACT (decl))
8448     equate_decl_number_to_die (decl, var_die);
8449
8450   if (! declaration && ! DECL_ABSTRACT (decl))
8451     {
8452       add_location_or_const_value_attribute (var_die, decl);
8453       add_pubname (decl, var_die);
8454     }
8455 }
8456
8457 /* Generate a DIE to represent a label identifier.  */
8458
8459 static void
8460 gen_label_die (decl, context_die)
8461      register tree decl;
8462      register dw_die_ref context_die;
8463 {
8464   register tree origin = decl_ultimate_origin (decl);
8465   register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die);
8466   register rtx insn;
8467   char label[MAX_ARTIFICIAL_LABEL_BYTES];
8468   char label2[MAX_ARTIFICIAL_LABEL_BYTES];
8469
8470   if (origin != NULL)
8471     add_abstract_origin_attribute (lbl_die, origin);
8472   else
8473     add_name_and_src_coords_attributes (lbl_die, decl);
8474
8475   if (DECL_ABSTRACT (decl))
8476     equate_decl_number_to_die (decl, lbl_die);
8477   else
8478     {
8479       insn = DECL_RTL (decl);
8480
8481       /* Deleted labels are programmer specified labels which have been
8482          eliminated because of various optimisations.  We still emit them
8483          here so that it is possible to put breakpoints on them.  */
8484       if (GET_CODE (insn) == CODE_LABEL
8485           || ((GET_CODE (insn) == NOTE
8486                && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
8487         {
8488           /* When optimization is enabled (via -O) some parts of the compiler 
8489              (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which 
8490              represent source-level labels which were explicitly declared by
8491              the user.  This really shouldn't be happening though, so catch
8492              it if it ever does happen.  */
8493           if (INSN_DELETED_P (insn))
8494             abort ();
8495
8496           sprintf (label2, INSN_LABEL_FMT, current_funcdef_number);
8497           ASM_GENERATE_INTERNAL_LABEL (label, label2,
8498                                        (unsigned) INSN_UID (insn));
8499           add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
8500         }
8501     }
8502 }
8503
8504 /* Generate a DIE for a lexical block.  */
8505
8506 static void
8507 gen_lexical_block_die (stmt, context_die, depth)
8508      register tree stmt;
8509      register dw_die_ref context_die;
8510      int depth;
8511 {
8512   register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die);
8513   char label[MAX_ARTIFICIAL_LABEL_BYTES];
8514
8515   if (! BLOCK_ABSTRACT (stmt))
8516     {
8517       ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
8518                                    BLOCK_NUMBER (stmt));
8519       add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
8520       ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
8521                                    BLOCK_NUMBER (stmt));
8522       add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
8523     }
8524
8525   decls_for_scope (stmt, stmt_die, depth);
8526 }
8527
8528 /* Generate a DIE for an inlined subprogram.  */
8529
8530 static void
8531 gen_inlined_subroutine_die (stmt, context_die, depth)
8532      register tree stmt;
8533      register dw_die_ref context_die;
8534      int depth;
8535 {
8536   if (! BLOCK_ABSTRACT (stmt))
8537     {
8538       register dw_die_ref subr_die
8539         = new_die (DW_TAG_inlined_subroutine, context_die);
8540       register tree decl = block_ultimate_origin (stmt);
8541       char label[MAX_ARTIFICIAL_LABEL_BYTES];
8542
8543       /* Emit info for the abstract instance first, if we haven't yet.  */
8544       gen_abstract_function (decl);
8545
8546       add_abstract_origin_attribute (subr_die, decl);
8547       ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
8548                                    BLOCK_NUMBER (stmt));
8549       add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
8550       ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
8551                                    BLOCK_NUMBER (stmt));
8552       add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
8553       decls_for_scope (stmt, subr_die, depth);
8554       current_function_has_inlines = 1;
8555     }
8556 }
8557
8558 /* Generate a DIE for a field in a record, or structure.  */
8559
8560 static void
8561 gen_field_die (decl, context_die)
8562      register tree decl;
8563      register dw_die_ref context_die;
8564 {
8565   register dw_die_ref decl_die = new_die (DW_TAG_member, context_die);
8566
8567   add_name_and_src_coords_attributes (decl_die, decl);
8568   add_type_attribute (decl_die, member_declared_type (decl),
8569                       TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
8570                       context_die);
8571
8572   /* If this is a bit field...  */
8573   if (DECL_BIT_FIELD_TYPE (decl))
8574     {
8575       add_byte_size_attribute (decl_die, decl);
8576       add_bit_size_attribute (decl_die, decl);
8577       add_bit_offset_attribute (decl_die, decl);
8578     }
8579
8580   if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
8581     add_data_member_location_attribute (decl_die, decl);
8582
8583   if (DECL_ARTIFICIAL (decl))
8584     add_AT_flag (decl_die, DW_AT_artificial, 1);
8585
8586   if (TREE_PROTECTED (decl))
8587     add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
8588
8589   else if (TREE_PRIVATE (decl))
8590     add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
8591 }
8592
8593 #if 0
8594 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
8595    Use modified_type_die instead.
8596    We keep this code here just in case these types of DIEs may be needed to
8597    represent certain things in other languages (e.g. Pascal) someday.  */
8598 static void
8599 gen_pointer_type_die (type, context_die)
8600      register tree type;
8601      register dw_die_ref context_die;
8602 {
8603   register dw_die_ref ptr_die
8604     = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die));
8605
8606   equate_type_number_to_die (type, ptr_die);
8607   add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
8608   add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
8609 }
8610
8611 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
8612    Use modified_type_die instead.
8613    We keep this code here just in case these types of DIEs may be needed to
8614    represent certain things in other languages (e.g. Pascal) someday.  */
8615 static void
8616 gen_reference_type_die (type, context_die)
8617      register tree type;
8618      register dw_die_ref context_die;
8619 {
8620   register dw_die_ref ref_die
8621     = new_die (DW_TAG_reference_type, scope_die_for (type, context_die));
8622
8623   equate_type_number_to_die (type, ref_die);
8624   add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
8625   add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
8626 }
8627 #endif
8628
8629 /* Generate a DIE for a pointer to a member type.  */
8630 static void
8631 gen_ptr_to_mbr_type_die (type, context_die)
8632      register tree type;
8633      register dw_die_ref context_die;
8634 {
8635   register dw_die_ref ptr_die
8636     = new_die (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die));
8637
8638   equate_type_number_to_die (type, ptr_die);
8639   add_AT_die_ref (ptr_die, DW_AT_containing_type,
8640                   lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
8641   add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
8642 }
8643
8644 /* Generate the DIE for the compilation unit.  */
8645
8646 static dw_die_ref
8647 gen_compile_unit_die (filename)
8648      register const char *filename;
8649 {
8650   register dw_die_ref die;
8651   char producer[250];
8652   char *wd = getpwd ();
8653   int language;
8654
8655   die = new_die (DW_TAG_compile_unit, NULL);
8656   add_name_attribute (die, filename);
8657
8658   if (wd != NULL && filename[0] != DIR_SEPARATOR)
8659     add_AT_string (die, DW_AT_comp_dir, wd);
8660
8661   sprintf (producer, "%s %s", language_string, version_string);
8662
8663 #ifdef MIPS_DEBUGGING_INFO
8664   /* The MIPS/SGI compilers place the 'cc' command line options in the producer
8665      string.  The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
8666      not appear in the producer string, the debugger reaches the conclusion
8667      that the object file is stripped and has no debugging information.
8668      To get the MIPS/SGI debugger to believe that there is debugging
8669      information in the object file, we add a -g to the producer string.  */
8670   if (debug_info_level > DINFO_LEVEL_TERSE)
8671     strcat (producer, " -g");
8672 #endif
8673
8674   add_AT_string (die, DW_AT_producer, producer);
8675
8676   if (strcmp (language_string, "GNU C++") == 0)
8677     language = DW_LANG_C_plus_plus;
8678   else if (strcmp (language_string, "GNU Ada") == 0)
8679     language = DW_LANG_Ada83;
8680   else if (strcmp (language_string, "GNU F77") == 0)
8681     language = DW_LANG_Fortran77;
8682   else if (strcmp (language_string, "GNU Pascal") == 0)
8683     language = DW_LANG_Pascal83;
8684   else if (flag_traditional)
8685     language = DW_LANG_C;
8686   else
8687     language = DW_LANG_C89;
8688
8689   add_AT_unsigned (die, DW_AT_language, language);
8690
8691   return die;
8692 }
8693
8694 /* Generate a DIE for a string type.  */
8695
8696 static void
8697 gen_string_type_die (type, context_die)
8698      register tree type;
8699      register dw_die_ref context_die;
8700 {
8701   register dw_die_ref type_die
8702     = new_die (DW_TAG_string_type, scope_die_for (type, context_die));
8703
8704   equate_type_number_to_die (type, type_die);
8705
8706   /* Fudge the string length attribute for now.  */
8707   
8708   /* TODO: add string length info.
8709    string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
8710                               bound_representation (upper_bound, 0, 'u'); */
8711 }
8712
8713 /* Generate the DIE for a base class.  */
8714
8715 static void
8716 gen_inheritance_die (binfo, context_die)
8717      register tree binfo;
8718      register dw_die_ref context_die;
8719 {
8720   dw_die_ref die = new_die (DW_TAG_inheritance, context_die);
8721
8722   add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
8723   add_data_member_location_attribute (die, binfo);
8724
8725   if (TREE_VIA_VIRTUAL (binfo))
8726     add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
8727   if (TREE_VIA_PUBLIC (binfo))
8728     add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
8729   else if (TREE_VIA_PROTECTED (binfo))
8730     add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
8731 }
8732
8733 /* Generate a DIE for a class member.  */
8734
8735 static void
8736 gen_member_die (type, context_die)
8737      register tree type;
8738      register dw_die_ref context_die;
8739 {
8740   register tree member;
8741   dw_die_ref child;
8742
8743   /* If this is not an incomplete type, output descriptions of each of its
8744      members. Note that as we output the DIEs necessary to represent the
8745      members of this record or union type, we will also be trying to output
8746      DIEs to represent the *types* of those members. However the `type'
8747      function (above) will specifically avoid generating type DIEs for member 
8748      types *within* the list of member DIEs for this (containing) type execpt 
8749      for those types (of members) which are explicitly marked as also being
8750      members of this (containing) type themselves.  The g++ front- end can
8751      force any given type to be treated as a member of some other
8752      (containing) type by setting the TYPE_CONTEXT of the given (member) type 
8753      to point to the TREE node representing the appropriate (containing)
8754      type.  */
8755
8756   /* First output info about the base classes.  */
8757   if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
8758     {
8759       register tree bases = TYPE_BINFO_BASETYPES (type);
8760       register int n_bases = TREE_VEC_LENGTH (bases);
8761       register int i;
8762
8763       for (i = 0; i < n_bases; i++)
8764         gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
8765     }
8766
8767   /* Now output info about the data members and type members.  */
8768   for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
8769     {
8770       /* If we thought we were generating minimal debug info for TYPE
8771          and then changed our minds, some of the member declarations
8772          may have already been defined.  Don't define them again, but
8773          do put them in the right order.  */
8774
8775       child = lookup_decl_die (member);
8776       if (child)
8777         splice_child_die (context_die, child);
8778       else
8779         gen_decl_die (member, context_die);
8780     }
8781
8782   /* Now output info about the function members (if any).  */
8783   for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
8784     {
8785       child = lookup_decl_die (member);
8786       if (child)
8787         splice_child_die (context_die, child);
8788       else
8789         gen_decl_die (member, context_die);
8790     }
8791 }
8792
8793 /* Generate a DIE for a structure or union type.  If TYPE_DECL_SUPPRESS_DEBUG
8794    is set, we pretend that the type was never defined, so we only get the
8795    member DIEs needed by later specification DIEs.  */
8796
8797 static void
8798 gen_struct_or_union_type_die (type, context_die)
8799      register tree type;
8800      register dw_die_ref context_die;
8801 {
8802   register dw_die_ref type_die = lookup_type_die (type);
8803   register dw_die_ref scope_die = 0;
8804   register int nested = 0;
8805   int complete = (TYPE_SIZE (type)
8806                   && (! TYPE_STUB_DECL (type)
8807                       || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
8808
8809   if (type_die && ! complete)
8810     return;
8811
8812   if (TYPE_CONTEXT (type) != NULL_TREE
8813       && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)))
8814     nested = 1;
8815
8816   scope_die = scope_die_for (type, context_die);
8817
8818   if (! type_die || (nested && scope_die == comp_unit_die))
8819     /* First occurrence of type or toplevel definition of nested class.  */
8820     {
8821       register dw_die_ref old_die = type_die;
8822
8823       type_die = new_die (TREE_CODE (type) == RECORD_TYPE
8824                           ? DW_TAG_structure_type : DW_TAG_union_type,
8825                           scope_die);
8826       equate_type_number_to_die (type, type_die);
8827       add_name_attribute (type_die, type_tag (type));
8828       if (old_die)
8829         add_AT_die_ref (type_die, DW_AT_specification, old_die);
8830     }
8831   else
8832     remove_AT (type_die, DW_AT_declaration);
8833
8834   /* If this type has been completed, then give it a byte_size attribute and
8835      then give a list of members.  */
8836   if (complete)
8837     {
8838       /* Prevent infinite recursion in cases where the type of some member of 
8839          this type is expressed in terms of this type itself.  */
8840       TREE_ASM_WRITTEN (type) = 1;
8841       add_byte_size_attribute (type_die, type);
8842       if (TYPE_STUB_DECL (type) != NULL_TREE)
8843         add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
8844
8845       /* If the first reference to this type was as the return type of an
8846          inline function, then it may not have a parent.  Fix this now.  */
8847       if (type_die->die_parent == NULL)
8848         add_child_die (scope_die, type_die);
8849
8850       push_decl_scope (type);
8851       gen_member_die (type, type_die);
8852       pop_decl_scope ();
8853
8854       /* GNU extension: Record what type our vtable lives in.  */
8855       if (TYPE_VFIELD (type))
8856         {
8857           tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
8858
8859           gen_type_die (vtype, context_die);
8860           add_AT_die_ref (type_die, DW_AT_containing_type,
8861                           lookup_type_die (vtype));
8862         }
8863     }
8864   else
8865     {
8866       add_AT_flag (type_die, DW_AT_declaration, 1);
8867
8868       /* We don't need to do this for function-local types.  */
8869       if (! decl_function_context (TYPE_STUB_DECL (type)))
8870         add_incomplete_type (type);
8871     }
8872 }
8873
8874 /* Generate a DIE for a subroutine _type_.  */
8875
8876 static void
8877 gen_subroutine_type_die (type, context_die)
8878      register tree type;
8879      register dw_die_ref context_die;
8880 {
8881   register tree return_type = TREE_TYPE (type);
8882   register dw_die_ref subr_die
8883     = new_die (DW_TAG_subroutine_type, scope_die_for (type, context_die));
8884
8885   equate_type_number_to_die (type, subr_die);
8886   add_prototyped_attribute (subr_die, type);
8887   add_type_attribute (subr_die, return_type, 0, 0, context_die);
8888   gen_formal_types_die (type, subr_die);
8889 }
8890
8891 /* Generate a DIE for a type definition */
8892
8893 static void
8894 gen_typedef_die (decl, context_die)
8895      register tree decl;
8896      register dw_die_ref context_die;
8897 {
8898   register dw_die_ref type_die;
8899   register tree origin;
8900
8901   if (TREE_ASM_WRITTEN (decl))
8902     return;
8903   TREE_ASM_WRITTEN (decl) = 1;
8904
8905   type_die = new_die (DW_TAG_typedef, context_die);
8906   origin = decl_ultimate_origin (decl);
8907   if (origin != NULL)
8908     add_abstract_origin_attribute (type_die, origin);
8909   else
8910     {
8911       register tree type;
8912       add_name_and_src_coords_attributes (type_die, decl);
8913       if (DECL_ORIGINAL_TYPE (decl))
8914         {
8915           type = DECL_ORIGINAL_TYPE (decl);
8916           equate_type_number_to_die (TREE_TYPE (decl), type_die);
8917         }
8918       else
8919         type = TREE_TYPE (decl);
8920       add_type_attribute (type_die, type, TREE_READONLY (decl),
8921                           TREE_THIS_VOLATILE (decl), context_die);
8922     }
8923
8924   if (DECL_ABSTRACT (decl))
8925     equate_decl_number_to_die (decl, type_die);
8926 }
8927
8928 /* Generate a type description DIE.  */
8929
8930 static void
8931 gen_type_die (type, context_die)
8932      register tree type;
8933      register dw_die_ref context_die;
8934 {
8935   int need_pop;
8936
8937   if (type == NULL_TREE || type == error_mark_node)
8938     return;
8939
8940   /* We are going to output a DIE to represent the unqualified version of
8941      this type (i.e. without any const or volatile qualifiers) so get the
8942      main variant (i.e. the unqualified version) of this type now.  */
8943   type = type_main_variant (type);
8944
8945   if (TREE_ASM_WRITTEN (type))
8946     return;
8947
8948   if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
8949       && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
8950     { 
8951       TREE_ASM_WRITTEN (type) = 1;
8952       gen_decl_die (TYPE_NAME (type), context_die);
8953       return;
8954     }
8955
8956   switch (TREE_CODE (type))
8957     {
8958     case ERROR_MARK:
8959       break;
8960
8961     case POINTER_TYPE:
8962     case REFERENCE_TYPE:
8963       /* We must set TREE_ASM_WRITTEN in case this is a recursive type.  This
8964          ensures that the gen_type_die recursion will terminate even if the
8965          type is recursive.  Recursive types are possible in Ada.  */
8966       /* ??? We could perhaps do this for all types before the switch
8967          statement.  */
8968       TREE_ASM_WRITTEN (type) = 1;
8969
8970       /* For these types, all that is required is that we output a DIE (or a
8971          set of DIEs) to represent the "basis" type.  */
8972       gen_type_die (TREE_TYPE (type), context_die);
8973       break;
8974
8975     case OFFSET_TYPE:
8976       /* This code is used for C++ pointer-to-data-member types. 
8977          Output a description of the relevant class type.  */
8978       gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
8979
8980       /* Output a description of the type of the object pointed to.  */
8981       gen_type_die (TREE_TYPE (type), context_die);
8982
8983       /* Now output a DIE to represent this pointer-to-data-member type
8984          itself.  */
8985       gen_ptr_to_mbr_type_die (type, context_die);
8986       break;
8987
8988     case SET_TYPE:
8989       gen_type_die (TYPE_DOMAIN (type), context_die);
8990       gen_set_type_die (type, context_die);
8991       break;
8992
8993     case FILE_TYPE:
8994       gen_type_die (TREE_TYPE (type), context_die);
8995       abort ();                 /* No way to represent these in Dwarf yet!  */
8996       break;
8997
8998     case FUNCTION_TYPE:
8999       /* Force out return type (in case it wasn't forced out already).  */
9000       gen_type_die (TREE_TYPE (type), context_die);
9001       gen_subroutine_type_die (type, context_die);
9002       break;
9003
9004     case METHOD_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;
9009
9010     case ARRAY_TYPE:
9011       if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
9012         {
9013           gen_type_die (TREE_TYPE (type), context_die);
9014           gen_string_type_die (type, context_die);
9015         }
9016       else
9017         gen_array_type_die (type, context_die);
9018       break;
9019
9020     case ENUMERAL_TYPE:
9021     case RECORD_TYPE:
9022     case UNION_TYPE:
9023     case QUAL_UNION_TYPE:
9024       /* If this is a nested type whose containing class hasn't been
9025          written out yet, writing it out will cover this one, too.
9026          This does not apply to instantiations of member class templates;
9027          they need to be added to the containing class as they are
9028          generated.  FIXME: This hurts the idea of combining type decls
9029          from multiple TUs, since we can't predict what set of template
9030          instantiations we'll get.  */
9031       if (TYPE_CONTEXT (type)
9032           && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
9033           && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
9034         {
9035           gen_type_die (TYPE_CONTEXT (type), context_die);
9036
9037           if (TREE_ASM_WRITTEN (type))
9038             return;
9039
9040           /* If that failed, attach ourselves to the stub.  */
9041           push_decl_scope (TYPE_CONTEXT (type));
9042           context_die = lookup_type_die (TYPE_CONTEXT (type));
9043           need_pop = 1;
9044         }
9045       else
9046         need_pop = 0;
9047
9048       if (TREE_CODE (type) == ENUMERAL_TYPE)
9049         gen_enumeration_type_die (type, context_die);
9050       else
9051         gen_struct_or_union_type_die (type, context_die);
9052
9053       if (need_pop)
9054         pop_decl_scope ();
9055
9056       /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
9057          it up if it is ever completed.  gen_*_type_die will set it for us
9058          when appropriate.  */
9059       return;
9060
9061     case VOID_TYPE:
9062     case INTEGER_TYPE:
9063     case REAL_TYPE:
9064     case COMPLEX_TYPE:
9065     case BOOLEAN_TYPE:
9066     case CHAR_TYPE:
9067       /* No DIEs needed for fundamental types.  */
9068       break;
9069
9070     case LANG_TYPE:
9071       /* No Dwarf representation currently defined.  */
9072       break;
9073
9074     default:
9075       abort ();
9076     }
9077
9078   TREE_ASM_WRITTEN (type) = 1;
9079 }
9080
9081 /* Generate a DIE for a tagged type instantiation.  */
9082
9083 static void
9084 gen_tagged_type_instantiation_die (type, context_die)
9085      register tree type;
9086      register dw_die_ref context_die;
9087 {
9088   if (type == NULL_TREE || type == error_mark_node)
9089     return;
9090
9091   /* We are going to output a DIE to represent the unqualified version of
9092      this type (i.e. without any const or volatile qualifiers) so make sure
9093      that we have the main variant (i.e. the unqualified version) of this
9094      type now.  */
9095   if (type != type_main_variant (type))
9096     abort ();
9097
9098   /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
9099      an instance of an unresolved type.  */
9100   
9101   switch (TREE_CODE (type))
9102     {
9103     case ERROR_MARK:
9104       break;
9105
9106     case ENUMERAL_TYPE:
9107       gen_inlined_enumeration_type_die (type, context_die);
9108       break;
9109
9110     case RECORD_TYPE:
9111       gen_inlined_structure_type_die (type, context_die);
9112       break;
9113
9114     case UNION_TYPE:
9115     case QUAL_UNION_TYPE:
9116       gen_inlined_union_type_die (type, context_die);
9117       break;
9118
9119     default:
9120       abort ();
9121     }
9122 }
9123
9124 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
9125    things which are local to the given block.  */
9126
9127 static void
9128 gen_block_die (stmt, context_die, depth)
9129      register tree stmt;
9130      register dw_die_ref context_die;
9131      int depth;
9132 {
9133   register int must_output_die = 0;
9134   register tree origin;
9135   register tree decl;
9136   register enum tree_code origin_code;
9137
9138   /* Ignore blocks never really used to make RTL.  */
9139
9140   if (stmt == NULL_TREE || !TREE_USED (stmt)
9141       || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
9142     return;
9143
9144   /* Determine the "ultimate origin" of this block.  This block may be an
9145      inlined instance of an inlined instance of inline function, so we have
9146      to trace all of the way back through the origin chain to find out what
9147      sort of node actually served as the original seed for the creation of
9148      the current block.  */
9149   origin = block_ultimate_origin (stmt);
9150   origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
9151
9152   /* Determine if we need to output any Dwarf DIEs at all to represent this
9153      block.  */
9154   if (origin_code == FUNCTION_DECL)
9155     /* The outer scopes for inlinings *must* always be represented.  We
9156        generate DW_TAG_inlined_subroutine DIEs for them.  (See below.) */
9157     must_output_die = 1;
9158   else
9159     {
9160       /* In the case where the current block represents an inlining of the
9161          "body block" of an inline function, we must *NOT* output any DIE for 
9162          this block because we have already output a DIE to represent the
9163          whole inlined function scope and the "body block" of any function
9164          doesn't really represent a different scope according to ANSI C
9165          rules.  So we check here to make sure that this block does not
9166          represent a "body block inlining" before trying to set the
9167          `must_output_die' flag.  */
9168       if (! is_body_block (origin ? origin : stmt))
9169         {
9170           /* Determine if this block directly contains any "significant"
9171              local declarations which we will need to output DIEs for.  */
9172           if (debug_info_level > DINFO_LEVEL_TERSE)
9173             /* We are not in terse mode so *any* local declaration counts
9174                as being a "significant" one.  */
9175             must_output_die = (BLOCK_VARS (stmt) != NULL);
9176           else
9177             /* We are in terse mode, so only local (nested) function
9178                definitions count as "significant" local declarations.  */
9179             for (decl = BLOCK_VARS (stmt);
9180                  decl != NULL; decl = TREE_CHAIN (decl))
9181               if (TREE_CODE (decl) == FUNCTION_DECL
9182                   && DECL_INITIAL (decl))
9183                 {
9184                   must_output_die = 1;
9185                   break;
9186                 }
9187         }
9188     }
9189
9190   /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
9191      DIE for any block which contains no significant local declarations at
9192      all.  Rather, in such cases we just call `decls_for_scope' so that any
9193      needed Dwarf info for any sub-blocks will get properly generated. Note
9194      that in terse mode, our definition of what constitutes a "significant"
9195      local declaration gets restricted to include only inlined function
9196      instances and local (nested) function definitions.  */
9197   if (must_output_die)
9198     {
9199       if (origin_code == FUNCTION_DECL)
9200         gen_inlined_subroutine_die (stmt, context_die, depth);
9201       else
9202         gen_lexical_block_die (stmt, context_die, depth);
9203     }
9204   else
9205     decls_for_scope (stmt, context_die, depth);
9206 }
9207
9208 /* Generate all of the decls declared within a given scope and (recursively)
9209    all of its sub-blocks.  */
9210
9211 static void
9212 decls_for_scope (stmt, context_die, depth)
9213      register tree stmt;
9214      register dw_die_ref context_die;
9215      int depth;
9216 {
9217   register tree decl;
9218   register tree subblocks;
9219
9220   /* Ignore blocks never really used to make RTL.  */
9221   if (stmt == NULL_TREE || ! TREE_USED (stmt))
9222     return;
9223
9224   /* Output the DIEs to represent all of the data objects and typedefs
9225      declared directly within this block but not within any nested
9226      sub-blocks.  Also, nested function and tag DIEs have been
9227      generated with a parent of NULL; fix that up now.  */
9228   for (decl = BLOCK_VARS (stmt);
9229        decl != NULL; decl = TREE_CHAIN (decl))
9230     {
9231       register dw_die_ref die;
9232
9233       if (TREE_CODE (decl) == FUNCTION_DECL)
9234         die = lookup_decl_die (decl);
9235       else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
9236         die = lookup_type_die (TREE_TYPE (decl));
9237       else
9238         die = NULL;
9239
9240       if (die != NULL && die->die_parent == NULL)
9241         add_child_die (context_die, die);
9242       else
9243         gen_decl_die (decl, context_die);
9244     }
9245
9246   /* Output the DIEs to represent all sub-blocks (and the items declared
9247      therein) of this block.  */
9248   for (subblocks = BLOCK_SUBBLOCKS (stmt);
9249        subblocks != NULL;
9250        subblocks = BLOCK_CHAIN (subblocks))
9251     gen_block_die (subblocks, context_die, depth + 1);
9252 }
9253
9254 /* Is this a typedef we can avoid emitting?  */
9255
9256 static inline int
9257 is_redundant_typedef (decl)
9258      register tree decl;
9259 {
9260   if (TYPE_DECL_IS_STUB (decl))
9261     return 1;
9262
9263   if (DECL_ARTIFICIAL (decl)
9264       && DECL_CONTEXT (decl)
9265       && is_tagged_type (DECL_CONTEXT (decl))
9266       && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
9267       && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
9268     /* Also ignore the artificial member typedef for the class name.  */
9269     return 1;
9270
9271   return 0;
9272 }
9273
9274 /* Generate Dwarf debug information for a decl described by DECL.  */
9275
9276 static void
9277 gen_decl_die (decl, context_die)
9278      register tree decl;
9279      register dw_die_ref context_die;
9280 {
9281   register tree origin;
9282
9283   if (TREE_CODE (decl) == ERROR_MARK)
9284     return;
9285
9286   /* If this ..._DECL node is marked to be ignored, then ignore it.  */
9287   if (DECL_IGNORED_P (decl))
9288     return;
9289
9290   switch (TREE_CODE (decl))
9291     {
9292     case CONST_DECL:
9293       /* The individual enumerators of an enum type get output when we output 
9294          the Dwarf representation of the relevant enum type itself.  */
9295       break;
9296
9297     case FUNCTION_DECL:
9298       /* Don't output any DIEs to represent mere function declarations,
9299          unless they are class members or explicit block externs.  */
9300       if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
9301           && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
9302         break;
9303
9304       /* Emit info for the abstract instance first, if we haven't yet.  */
9305       origin = decl_ultimate_origin (decl);
9306       if (origin)
9307         gen_abstract_function (origin);
9308
9309       if (debug_info_level > DINFO_LEVEL_TERSE)
9310         {
9311           /* Before we describe the FUNCTION_DECL itself, make sure that we
9312              have described its return type.  */
9313           gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
9314
9315           /* And its virtual context.  */
9316           if (DECL_VINDEX (decl) != NULL_TREE)
9317             gen_type_die (DECL_CONTEXT (decl), context_die);
9318
9319           /* And its containing type.  */
9320           origin = decl_class_context (decl);
9321           if (origin != NULL_TREE)
9322             gen_type_die_for_member (origin, decl, context_die);
9323         }
9324
9325       /* Now output a DIE to represent the function itself.  */
9326       gen_subprogram_die (decl, context_die);
9327       break;
9328
9329     case TYPE_DECL:
9330       /* If we are in terse mode, don't generate any DIEs to represent any
9331          actual typedefs.  */
9332       if (debug_info_level <= DINFO_LEVEL_TERSE)
9333         break;
9334
9335       /* In the special case of a TYPE_DECL node representing the 
9336          declaration of some type tag, if the given TYPE_DECL is marked as
9337          having been instantiated from some other (original) TYPE_DECL node
9338          (e.g. one which was generated within the original definition of an
9339          inline function) we have to generate a special (abbreviated)
9340          DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type 
9341          DIE here.  */
9342       if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
9343         {
9344           gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
9345           break;
9346         }
9347
9348       if (is_redundant_typedef (decl))
9349         gen_type_die (TREE_TYPE (decl), context_die);
9350       else
9351         /* Output a DIE to represent the typedef itself.  */
9352         gen_typedef_die (decl, context_die);
9353       break;
9354
9355     case LABEL_DECL:
9356       if (debug_info_level >= DINFO_LEVEL_NORMAL)
9357         gen_label_die (decl, context_die);
9358       break;
9359
9360     case VAR_DECL:
9361       /* If we are in terse mode, don't generate any DIEs to represent any
9362          variable declarations or definitions.  */
9363       if (debug_info_level <= DINFO_LEVEL_TERSE)
9364         break;
9365
9366       /* Output any DIEs that are needed to specify the type of this data
9367          object.  */
9368       gen_type_die (TREE_TYPE (decl), context_die);
9369
9370       /* And its containing type.  */
9371       origin = decl_class_context (decl);
9372       if (origin != NULL_TREE)
9373         gen_type_die_for_member (origin, decl, context_die);
9374
9375       /* Now output the DIE to represent the data object itself.  This gets
9376          complicated because of the possibility that the VAR_DECL really
9377          represents an inlined instance of a formal parameter for an inline
9378          function.  */
9379       origin = decl_ultimate_origin (decl);
9380       if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
9381         gen_formal_parameter_die (decl, context_die);
9382       else
9383         gen_variable_die (decl, context_die);
9384       break;
9385
9386     case FIELD_DECL:
9387       /* Ignore the nameless fields that are used to skip bits, but
9388          handle C++ anonymous unions.  */
9389       if (DECL_NAME (decl) != NULL_TREE
9390           || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
9391         {
9392           gen_type_die (member_declared_type (decl), context_die);
9393           gen_field_die (decl, context_die);
9394         }
9395       break;
9396
9397     case PARM_DECL:
9398       gen_type_die (TREE_TYPE (decl), context_die);
9399       gen_formal_parameter_die (decl, context_die);
9400       break;
9401
9402     case NAMESPACE_DECL:
9403       /* Ignore for now.  */
9404       break;
9405
9406     default:
9407       abort ();
9408     }
9409 }
9410 \f
9411 /* Add Ada "use" clause information for SGI Workshop debugger.  */
9412
9413 void
9414 dwarf2out_add_library_unit_info (filename, context_list)
9415      const char *filename;
9416      const char *context_list;
9417 {
9418   unsigned int file_index;
9419
9420   if (filename != NULL)
9421     {
9422       dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die);
9423       tree context_list_decl 
9424         = build_decl (LABEL_DECL, get_identifier (context_list),
9425                       void_type_node);
9426
9427       TREE_PUBLIC (context_list_decl) = TRUE;
9428       add_name_attribute (unit_die, context_list);
9429       file_index = lookup_filename (filename);
9430       add_AT_unsigned (unit_die, DW_AT_decl_file, file_index);
9431       add_pubname (context_list_decl, unit_die);
9432     }
9433 }
9434
9435 /* Write the debugging output for DECL.  */
9436
9437 void
9438 dwarf2out_decl (decl)
9439      register tree decl;
9440 {
9441   register dw_die_ref context_die = comp_unit_die;
9442
9443   if (TREE_CODE (decl) == ERROR_MARK)
9444     return;
9445
9446   /* If this ..._DECL node is marked to be ignored, then ignore it.  */
9447   if (DECL_IGNORED_P (decl))
9448     return;
9449
9450   switch (TREE_CODE (decl))
9451     {
9452     case FUNCTION_DECL:
9453       /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a 
9454          builtin function.  Explicit programmer-supplied declarations of
9455          these same functions should NOT be ignored however.  */
9456       if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl))
9457         return;
9458
9459       /* What we would really like to do here is to filter out all mere
9460          file-scope declarations of file-scope functions which are never
9461          referenced later within this translation unit (and keep all of ones
9462          that *are* referenced later on) but we aren't clairvoyant, so we have 
9463          no idea which functions will be referenced in the future (i.e. later 
9464          on within the current translation unit). So here we just ignore all
9465          file-scope function declarations which are not also definitions.  If 
9466          and when the debugger needs to know something about these functions,
9467          it will have to hunt around and find the DWARF information associated 
9468          with the definition of the function.  Note that we can't just check
9469          `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
9470          definitions and which ones represent mere declarations.  We have to
9471          check `DECL_INITIAL' instead. That's because the C front-end
9472          supports some weird semantics for "extern inline" function
9473          definitions.  These can get inlined within the current translation
9474          unit (an thus, we need to generate DWARF info for their abstract
9475          instances so that the DWARF info for the concrete inlined instances
9476          can have something to refer to) but the compiler never generates any 
9477          out-of-lines instances of such things (despite the fact that they
9478          *are* definitions).  The important point is that the C front-end
9479          marks these "extern inline" functions as DECL_EXTERNAL, but we need
9480          to generate DWARF for them anyway. Note that the C++ front-end also
9481          plays some similar games for inline function definitions appearing
9482          within include files which also contain 
9483          `#pragma interface' pragmas.  */
9484       if (DECL_INITIAL (decl) == NULL_TREE)
9485         return;
9486
9487       /* If we're a nested function, initially use a parent of NULL; if we're
9488          a plain function, this will be fixed up in decls_for_scope.  If
9489          we're a method, it will be ignored, since we already have a DIE.  */
9490       if (decl_function_context (decl))
9491         context_die = NULL;
9492
9493       break;
9494
9495     case VAR_DECL:
9496       /* Ignore this VAR_DECL if it refers to a file-scope extern data object 
9497          declaration and if the declaration was never even referenced from
9498          within this entire compilation unit.  We suppress these DIEs in
9499          order to save space in the .debug section (by eliminating entries
9500          which are probably useless).  Note that we must not suppress
9501          block-local extern declarations (whether used or not) because that
9502          would screw-up the debugger's name lookup mechanism and cause it to
9503          miss things which really ought to be in scope at a given point.  */
9504       if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
9505         return;
9506
9507       /* If we are in terse mode, don't generate any DIEs to represent any
9508          variable declarations or definitions.  */
9509       if (debug_info_level <= DINFO_LEVEL_TERSE)
9510         return;
9511       break;
9512
9513     case TYPE_DECL:
9514       /* Don't emit stubs for types unless they are needed by other DIEs.  */
9515       if (TYPE_DECL_SUPPRESS_DEBUG (decl))
9516         return;
9517
9518       /* Don't bother trying to generate any DIEs to represent any of the
9519          normal built-in types for the language we are compiling.  */
9520       if (DECL_SOURCE_LINE (decl) == 0)
9521         {
9522           /* OK, we need to generate one for `bool' so GDB knows what type
9523              comparisons have.  */
9524           if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
9525                == DW_LANG_C_plus_plus)
9526               && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE)
9527             modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
9528
9529           return;
9530         }
9531
9532       /* If we are in terse mode, don't generate any DIEs for types.  */
9533       if (debug_info_level <= DINFO_LEVEL_TERSE)
9534         return;
9535
9536       /* If we're a function-scope tag, initially use a parent of NULL;
9537          this will be fixed up in decls_for_scope.  */
9538       if (decl_function_context (decl))
9539         context_die = NULL;
9540
9541       break;
9542
9543     default:
9544       return;
9545     }
9546
9547   gen_decl_die (decl, context_die);
9548 }
9549
9550 /* Output a marker (i.e. a label) for the beginning of the generated code for
9551    a lexical block.  */
9552
9553 void
9554 dwarf2out_begin_block (blocknum)
9555      register unsigned blocknum;
9556 {
9557   function_section (current_function_decl);
9558   ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
9559 }
9560
9561 /* Output a marker (i.e. a label) for the end of the generated code for a
9562    lexical block.  */
9563
9564 void
9565 dwarf2out_end_block (blocknum)
9566      register unsigned blocknum;
9567 {
9568   function_section (current_function_decl);
9569   ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
9570 }
9571
9572 /* We've decided not to emit any debugging information for BLOCK; make
9573    sure that we don't end up with orphans as a result.  */
9574
9575 void
9576 dwarf2out_ignore_block (block)
9577      tree block;
9578 {
9579   tree decl;
9580   for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
9581     {
9582       dw_die_ref die;
9583
9584       if (TREE_CODE (decl) == FUNCTION_DECL)
9585         die = lookup_decl_die (decl);
9586       else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
9587         die = lookup_type_die (TREE_TYPE (decl));
9588       else
9589         die = NULL;
9590
9591       /* Just give them a dummy value for parent so dwarf2out_finish
9592          doesn't blow up; we would use add_child_die if we really
9593          wanted to add them to comp_unit_die's children.  */
9594       if (die && die->die_parent == 0)
9595         die->die_parent = comp_unit_die;
9596     }
9597 }
9598
9599 /* Output a marker (i.e. a label) at a point in the assembly code which
9600    corresponds to a given source level label.  */
9601
9602 void
9603 dwarf2out_label (insn)
9604      register rtx insn;
9605 {
9606   char label[MAX_ARTIFICIAL_LABEL_BYTES];
9607
9608   if (debug_info_level >= DINFO_LEVEL_NORMAL)
9609     {
9610       function_section (current_function_decl);
9611       sprintf (label, INSN_LABEL_FMT, current_funcdef_number);
9612       ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, label,
9613                                  (unsigned) INSN_UID (insn));
9614     }
9615 }
9616
9617 /* Lookup a filename (in the list of filenames that we know about here in
9618    dwarf2out.c) and return its "index".  The index of each (known) filename is
9619    just a unique number which is associated with only that one filename.
9620    We need such numbers for the sake of generating labels
9621    (in the .debug_sfnames section) and references to those
9622    files  numbers (in the .debug_srcinfo and.debug_macinfo sections).
9623    If the filename given as an argument is not found in our current list,
9624    add it to the list and assign it the next available unique index number.
9625    In order to speed up searches, we remember the index of the filename
9626    was looked up last.  This handles the majority of all searches.  */
9627
9628 static unsigned
9629 lookup_filename (file_name)
9630      const char *file_name;
9631 {
9632   static unsigned last_file_lookup_index = 0;
9633   register unsigned i;
9634
9635   /* Check to see if the file name that was searched on the previous call
9636      matches this file name. If so, return the index.  */
9637   if (last_file_lookup_index != 0)
9638     if (strcmp (file_name, file_table[last_file_lookup_index]) == 0)
9639       return last_file_lookup_index;
9640
9641   /* Didn't match the previous lookup, search the table */
9642   for (i = 1; i < file_table_in_use; ++i)
9643     if (strcmp (file_name, file_table[i]) == 0)
9644       {
9645         last_file_lookup_index = i;
9646         return i;
9647       }
9648
9649   /* Prepare to add a new table entry by making sure there is enough space in 
9650      the table to do so.  If not, expand the current table.  */
9651   if (file_table_in_use == file_table_allocated)
9652     {
9653       file_table_allocated += FILE_TABLE_INCREMENT;
9654       file_table
9655         = (char **) xrealloc (file_table,
9656                               file_table_allocated * sizeof (char *));
9657     }
9658
9659   /* Add the new entry to the end of the filename table.  */
9660   file_table[file_table_in_use] = xstrdup (file_name);
9661   last_file_lookup_index = file_table_in_use++;
9662
9663   return last_file_lookup_index;
9664 }
9665
9666 /* Output a label to mark the beginning of a source code line entry
9667    and record information relating to this source line, in
9668    'line_info_table' for later output of the .debug_line section.  */
9669
9670 void
9671 dwarf2out_line (filename, line)
9672      register const char *filename;
9673      register unsigned line;
9674 {
9675   if (debug_info_level >= DINFO_LEVEL_NORMAL)
9676     {
9677       function_section (current_function_decl);
9678
9679       if (DWARF2_ASM_LINE_DEBUG_INFO)
9680         {
9681           static const char *lastfile;
9682
9683           /* Emit the .file and .loc directives understood by GNU as.  */
9684           if (lastfile == 0 || strcmp (filename, lastfile))
9685             {
9686               if (lastfile == 0)
9687                 ggc_add_string_root ((char **) &lastfile, 1);
9688
9689               fprintf (asm_out_file, "\t.file 0 \"%s\"\n", filename);
9690               lastfile = filename;
9691             }
9692
9693           fprintf (asm_out_file, "\t.loc 0 %d 0\n", line);
9694
9695           /* Indicate that line number info exists.  */
9696           ++line_info_table_in_use;
9697
9698           /* Indicate that multiple line number tables exist.  */
9699           if (DECL_SECTION_NAME (current_function_decl))
9700             ++separate_line_info_table_in_use;
9701         }
9702       else if (DECL_SECTION_NAME (current_function_decl))
9703         {
9704           register dw_separate_line_info_ref line_info;
9705           ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
9706                                      separate_line_info_table_in_use);
9707           if (flag_debug_asm)
9708             fprintf (asm_out_file, "\t%s line %d", ASM_COMMENT_START, line);
9709           fputc ('\n', asm_out_file);
9710
9711           /* expand the line info table if necessary */
9712           if (separate_line_info_table_in_use
9713               == separate_line_info_table_allocated)
9714             {
9715               separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
9716               separate_line_info_table
9717                 = (dw_separate_line_info_ref)
9718                   xrealloc (separate_line_info_table,
9719                             separate_line_info_table_allocated
9720                             * sizeof (dw_separate_line_info_entry));
9721             }
9722
9723           /* Add the new entry at the end of the line_info_table.  */
9724           line_info
9725             = &separate_line_info_table[separate_line_info_table_in_use++];
9726           line_info->dw_file_num = lookup_filename (filename);
9727           line_info->dw_line_num = line;
9728           line_info->function = current_funcdef_number;
9729         }
9730       else
9731         {
9732           register dw_line_info_ref line_info;
9733
9734           ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
9735                                      line_info_table_in_use);
9736           if (flag_debug_asm)
9737             fprintf (asm_out_file, "\t%s line %d", ASM_COMMENT_START, line);
9738           fputc ('\n', asm_out_file);
9739
9740           /* Expand the line info table if necessary.  */
9741           if (line_info_table_in_use == line_info_table_allocated)
9742             {
9743               line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
9744               line_info_table
9745                 = (dw_line_info_ref)
9746                   xrealloc (line_info_table,
9747                             (line_info_table_allocated
9748                              * sizeof (dw_line_info_entry)));
9749             }
9750
9751           /* Add the new entry at the end of the line_info_table.  */
9752           line_info = &line_info_table[line_info_table_in_use++];
9753           line_info->dw_file_num = lookup_filename (filename);
9754           line_info->dw_line_num = line;
9755         }
9756     }
9757 }
9758
9759 /* Record the beginning of a new source file, for later output
9760    of the .debug_macinfo section.  At present, unimplemented.  */
9761
9762 void
9763 dwarf2out_start_source_file (filename)
9764      register const char *filename ATTRIBUTE_UNUSED;
9765 {
9766 }
9767
9768 /* Record the end of a source file, for later output
9769    of the .debug_macinfo section.  At present, unimplemented.  */
9770
9771 void
9772 dwarf2out_end_source_file ()
9773 {
9774 }
9775
9776 /* Called from check_newline in c-parse.y.  The `buffer' parameter contains
9777    the tail part of the directive line, i.e. the part which is past the
9778    initial whitespace, #, whitespace, directive-name, whitespace part.  */
9779
9780 void
9781 dwarf2out_define (lineno, buffer)
9782      register unsigned lineno ATTRIBUTE_UNUSED;
9783      register const char *buffer ATTRIBUTE_UNUSED;
9784 {
9785   static int initialized = 0;
9786   if (!initialized)
9787     {
9788       dwarf2out_start_source_file (primary_filename);
9789       initialized = 1;
9790     }
9791 }
9792
9793 /* Called from check_newline in c-parse.y.  The `buffer' parameter contains
9794    the tail part of the directive line, i.e. the part which is past the
9795    initial whitespace, #, whitespace, directive-name, whitespace part.  */
9796
9797 void
9798 dwarf2out_undef (lineno, buffer)
9799      register unsigned lineno ATTRIBUTE_UNUSED;
9800      register const char *buffer ATTRIBUTE_UNUSED;
9801 {
9802 }
9803
9804 /* Set up for Dwarf output at the start of compilation.  */
9805
9806 void
9807 dwarf2out_init (asm_out_file, main_input_filename)
9808      register FILE *asm_out_file;
9809      register char *main_input_filename;
9810 {
9811   /* Remember the name of the primary input file.  */
9812   primary_filename = main_input_filename;
9813
9814   /* Allocate the initial hunk of the file_table.  */
9815   file_table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *));
9816   file_table_allocated = FILE_TABLE_INCREMENT;
9817
9818   /* Skip the first entry - file numbers begin at 1.  */
9819   file_table_in_use = 1;
9820
9821   /* Allocate the initial hunk of the decl_die_table.  */
9822   decl_die_table
9823     = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref));
9824   decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
9825   decl_die_table_in_use = 0;
9826
9827   /* Allocate the initial hunk of the decl_scope_table.  */
9828   decl_scope_table
9829     = (tree *) xcalloc (DECL_SCOPE_TABLE_INCREMENT, sizeof (tree));
9830   decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT;
9831   decl_scope_depth = 0;
9832
9833   /* Allocate the initial hunk of the abbrev_die_table.  */
9834   abbrev_die_table
9835     = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT,
9836                               sizeof (dw_die_ref));
9837   abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
9838   /* Zero-th entry is allocated, but unused */
9839   abbrev_die_table_in_use = 1;
9840
9841   /* Allocate the initial hunk of the line_info_table.  */
9842   line_info_table
9843     = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT,
9844                                   sizeof (dw_line_info_entry));
9845   line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
9846   /* Zero-th entry is allocated, but unused */
9847   line_info_table_in_use = 1;
9848
9849   /* Generate the initial DIE for the .debug section.  Note that the (string) 
9850      value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
9851      will (typically) be a relative pathname and that this pathname should be 
9852      taken as being relative to the directory from which the compiler was
9853      invoked when the given (base) source file was compiled.  */
9854   comp_unit_die = gen_compile_unit_die (main_input_filename);
9855
9856   if (ggc_p)
9857     {
9858       VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray");
9859       ggc_add_rtx_varray_root (&used_rtx_varray, 1);
9860     }
9861
9862   ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
9863   ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label, ABBREV_SECTION_LABEL, 0);
9864   if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
9865     ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
9866   else
9867     strcpy (text_section_label, stripattributes (TEXT_SECTION));
9868   ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label, 
9869                                DEBUG_INFO_SECTION_LABEL, 0);
9870   ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label, 
9871                                DEBUG_LINE_SECTION_LABEL, 0);
9872
9873   ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
9874   ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
9875   if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
9876     {
9877       ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
9878       ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
9879     }
9880   ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION);
9881   ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
9882   ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
9883   ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
9884 }
9885
9886 /* Output stuff that dwarf requires at the end of every file,
9887    and generate the DWARF-2 debugging info.  */
9888
9889 void
9890 dwarf2out_finish ()
9891 {
9892   limbo_die_node *node, *next_node;
9893   dw_die_ref die;
9894
9895   /* Traverse the limbo die list, and add parent/child links.  The only
9896      dies without parents that should be here are concrete instances of
9897      inline functions, and the comp_unit_die.  We can ignore the comp_unit_die.
9898      For concrete instances, we can get the parent die from the abstract
9899      instance.  */
9900   for (node = limbo_die_list; node; node = next_node)
9901     {
9902       next_node = node->next;
9903       die = node->die;
9904
9905       if (die->die_parent == NULL)
9906         {
9907           dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
9908           if (origin)
9909             add_child_die (origin->die_parent, die);
9910           else if (die == comp_unit_die)
9911             ;
9912           else
9913             abort ();
9914         }
9915       free (node);
9916     }
9917   limbo_die_list = NULL;
9918
9919   /* Walk through the list of incomplete types again, trying once more to
9920      emit full debugging info for them.  */
9921   retry_incomplete_types ();
9922
9923   /* Traverse the DIE's, reverse their lists of attributes and children,
9924      and add add sibling attributes to those DIE's that have children.  */
9925   add_sibling_attributes (comp_unit_die);
9926
9927   /* Output a terminator label for the .text section.  */
9928   fputc ('\n', asm_out_file);
9929   ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
9930   ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
9931
9932 #if 0
9933   /* Output a terminator label for the .data section.  */
9934   fputc ('\n', asm_out_file);
9935   ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION);
9936   ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, DATA_END_LABEL, 0);
9937
9938   /* Output a terminator label for the .bss section.  */
9939   fputc ('\n', asm_out_file);
9940   ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION);
9941   ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BSS_END_LABEL, 0);
9942 #endif
9943
9944   /* Output the source line correspondence table.  */
9945   if (line_info_table_in_use > 1 || separate_line_info_table_in_use)
9946     {
9947       if (! DWARF2_ASM_LINE_DEBUG_INFO)
9948         {
9949           fputc ('\n', asm_out_file);
9950           ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
9951           output_line_info ();
9952         }
9953
9954       /* We can only use the low/high_pc attributes if all of the code
9955          was in .text.  */
9956       if (separate_line_info_table_in_use == 0)
9957         {
9958           add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
9959           add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
9960         }
9961
9962       add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list,
9963                          debug_line_section_label);
9964     }
9965
9966 #if 0 /* unimplemented */
9967   if (debug_info_level >= DINFO_LEVEL_VERBOSE && primary)
9968     add_AT_unsigned (die, DW_AT_macro_info, 0);
9969 #endif
9970
9971   /* Output the abbreviation table.  */
9972   fputc ('\n', asm_out_file);
9973   ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
9974   build_abbrev_table (comp_unit_die);
9975   output_abbrev_section ();
9976
9977   /* Initialize the beginning DIE offset - and calculate sizes/offsets.   */
9978   next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
9979   calc_die_sizes (comp_unit_die);
9980
9981   /* Output debugging information.  */
9982   fputc ('\n', asm_out_file);
9983   ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION);
9984   output_compilation_unit_header ();
9985   output_die (comp_unit_die);
9986
9987   if (pubname_table_in_use)
9988     {
9989       /* Output public names table.  */
9990       fputc ('\n', asm_out_file);
9991       ASM_OUTPUT_SECTION (asm_out_file, PUBNAMES_SECTION);
9992       output_pubnames ();
9993     }
9994
9995   /* We only put functions in the arange table, so don't write it out if
9996      we don't have any.  */
9997   if (fde_table_in_use)
9998     {
9999       /* Output the address range information.  */
10000       fputc ('\n', asm_out_file);
10001       ASM_OUTPUT_SECTION (asm_out_file, ARANGES_SECTION);
10002       output_aranges ();
10003     }
10004 }
10005 #endif /* DWARF2_DEBUGGING_INFO */