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