OSDN Git Service

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