OSDN Git Service

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