OSDN Git Service

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