OSDN Git Service

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