OSDN Git Service

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