OSDN Git Service

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