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