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