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