OSDN Git Service

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