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