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