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