OSDN Git Service

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