OSDN Git Service

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