OSDN Git Service

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