OSDN Git Service

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