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