OSDN Git Service

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